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?
call it Ralph and all will work. If Ralph is already used, call it Phred. My usual name for such is "expansion_space" Erik
The problem is that I have way too many non-contiguous "reserved" field. Is there a way to leave it unnamed? Thanks, Anh
I think giving it a name is probably a better idea: At least then you can set a breakpoint on "reserved_027" to ensure that nothing is (unwittingly) accessing it. And you can easily do a text search for "reserved_" to find them all. And, in the future version that starts using one of them, your can say "reserved_459 is now used for hyperdrive_warp_factor" or whatever.
Implicit in my previous post was the suggestion that you use a standard format; eg, call them all reserved_xxx, where xxx is just a 3-digit (or whatever) number. Using a fixed 3 (or whatever) digits means that a simple text sort (eg, as in the uVision browser) will put them in the right order - otherwise you get reserved_9 coming before reserved_199 in a sorted list! Also, a fixed size makes it easier to construct a regular expression to find them all
"The problem is that I have way too many non-contiguous 'reserved' field." Why?? Does this not suggest something that needs to be fixed in your design? As you say yourself that there's "way too many," why don't you get rid of 'em?!
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}
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; }
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; }