This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

unnamed variable as place holder inside struct

Does any one know how to create an unnamed variable for place holder in a struct? I know you can do it in bitfiled.

Example:

struct S
{
   int a;
   int b;
   int[5]; //reserved 5 ints but dont' need to name it.
   int c;
   int d;

   int  bit0 : 1;
   int       : 6;
   int  bit7 : 1;

}
</pre?

Parents
  • If your objective is simply to avoid the drudgery of typing 'reserved' structure member names, this short AWK script will do it for you:

    BEGIN { FS = "[" }
    
    /[ \t]+(char|short|int|long)\[/ {
    	count_str = sprintf("%03d", count++)
    	$0 = $1 " reserved_" count_str "[" $2
    }
    
    {print}
    Such that:
    struct S
    {
       int a;
       int b;
       int[5]; //reserved 5 ints but dont' need to name it.
       char[5]; //reserved 5 ints but dont' need to name it.
       long[5]; //reserved 5 ints but dont' need to name it.
       int[5]; //reserved 5 ints but dont' need to name it.
       int c;
       int d;
    
       int  bit0 : 1;
       int       : 6;
       int  bit7 : 1;
    }
    becomes
    struct S
    {
       int a;
       int b;
       int reserved_000[5]; //reserved 5 ints but dont' need to name it.
       char reserved_001[5]; //reserved 5 ints but dont' need to name it.
       long reserved_002[5]; //reserved 5 ints but dont' need to name it.
       int reserved_003[5]; //reserved 5 ints but dont' need to name it.
       int c;
       int d;
    
       int  bit0 : 1;
       int       : 6;
       int  bit7 : 1;
    }
    A native Win32 AWK is available at http://unxutils.sourceforge.net/

Reply
  • If your objective is simply to avoid the drudgery of typing 'reserved' structure member names, this short AWK script will do it for you:

    BEGIN { FS = "[" }
    
    /[ \t]+(char|short|int|long)\[/ {
    	count_str = sprintf("%03d", count++)
    	$0 = $1 " reserved_" count_str "[" $2
    }
    
    {print}
    Such that:
    struct S
    {
       int a;
       int b;
       int[5]; //reserved 5 ints but dont' need to name it.
       char[5]; //reserved 5 ints but dont' need to name it.
       long[5]; //reserved 5 ints but dont' need to name it.
       int[5]; //reserved 5 ints but dont' need to name it.
       int c;
       int d;
    
       int  bit0 : 1;
       int       : 6;
       int  bit7 : 1;
    }
    becomes
    struct S
    {
       int a;
       int b;
       int reserved_000[5]; //reserved 5 ints but dont' need to name it.
       char reserved_001[5]; //reserved 5 ints but dont' need to name it.
       long reserved_002[5]; //reserved 5 ints but dont' need to name it.
       int reserved_003[5]; //reserved 5 ints but dont' need to name it.
       int c;
       int d;
    
       int  bit0 : 1;
       int       : 6;
       int  bit7 : 1;
    }
    A native Win32 AWK is available at http://unxutils.sourceforge.net/

Children
No data