Reputation: 1151
I am on Linux, coding in C and tried to play with the align attribute for argv variables, but with no luck :
How could we cause the argv arguments (each of it) to be aligned to a defined boundary, say 16 bits, without copying it first to an aligned variable, via memcpy or alternatives ?
Is it even possible ?
Upvotes: 0
Views: 193
Reputation: 148880
In some implementations, the argv variables can point directly to the original command line where first delimiter (space) after each argument has been replaced with a null. In such an implementation it is clear that alignement is what it is and cannot be controled !
Upvotes: 1
Reputation: 144685
It is not possible. The align attribute tells the compiler how to align structures for which it generates code and data. It also tells the compiler about the actual alignment of extern structures and data generated by other code.
The argv arguments are supplied by the C startup code or the OS directly. No assumptions should be made about their alignment beyond the implicit self alignment of the pointer array. You cannot change that with compiler attributes, not is it advisable to force the compiler to make other assumptions.
Upvotes: 2