Thread: declaring filler space in a struct

  1. #1
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Chappell Hill, Texas

    declaring filler space in a struct

    Is there a way to declare space in a struct as unused / filler / pad, in such as way as to not have to provide an identifier?

    For example,

    struct foo { 
       int  .  ;      // just 4 bytes, padding for later, don't need it now 
       int myval ; 
    } ;
    Mainframe assembler programmer by trade. C coder when I can.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    You can have unnamed bit-fields.
    int main()
        struct foo {
            int : 32;
            int myval;
        } bar;
        bar.myval = 42;
        printf("%zd\n",offsetof(struct foo,myval));
        return 0;
    Though 99% of people will just say this and think no more of it.
    struct foo {
      int dummy;
      int myval;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. declaring a struct with its fields as a struct
    By starmandell in forum C Programming
    Replies: 1
    Last Post: 03-29-2011, 06:54 AM
  2. Declaring a struct before defining it
    By hardi in forum C Programming
    Replies: 4
    Last Post: 12-07-2006, 01:51 PM
  3. Declaring struct problem
    By _DrMario_ in forum C Programming
    Replies: 2
    Last Post: 12-04-2006, 10:02 AM
  4. Help with writing a disk filler applet
    By mlupo in forum C Programming
    Replies: 8
    Last Post: 01-18-2006, 02:39 PM
  5. Declaring classes in global space
    By Rune Hunter in forum C++ Programming
    Replies: 12
    Last Post: 10-12-2005, 02:46 PM

Tags for this Thread