Isn't it time there was a standard align statement?



It'd be really pleasant (in my opinion) if the next revision of the
C language actually allowed some portable control over data
alignment.

Compiler-specific mechanisms for this stuff are so varied that
it becomes impossible to even abstract the details away behind
preprocessor macros.

What I'd like to see:

/* per structure alignment */
align(16) struct xyz {
char x;
char y;
int z;
};

/* per member alignment (obviously padding before the first
member is illegal, so the entire structure would become aligned
in this case */
align(16) struct xyz {
align(16) char x;
char y;
int z;
};

/* per variable alignment */
align(16) unsigned int x;

I don't care about the syntax.

Now, obviously, C is meant to be implemented on everything from
self-aware weather-control mainframes, to motorized tie racks,
so in the case of the host implementation not supporting the specified
alignment, a warning should be emitted and either the closest or
natural alignment should be given. Warnings can obviously be made
fatal with compiler specific switches - and that's no business of the
language.

It just seems that this really should be standardized as it clearly
is useful for a vast number of programmers who need to get close to the
hardware but don't want to stray into assembly code (think Altivec,
SSE).
Sounds like EXACTLY the point of the C language, doesn't it?

I wouldn't mind so much if compiler implementors had come up with a
vaguely portable way of doing this, but they haven't even come close.
GCC and Intel have won joint first prize for 'most pleasant
implementation'
though (__attribute__ or _declspec()).

cheers,
MC

.



Relevant Pages

  • Re: Are _T() and TEXT() macros equivalent?
    ... are not concerned if a char takes 1 byte or 100. ... since the language defines an object ... various ramifications of using and not using the switch. ... Why the fixation on basing the meaning of the keyword "char" on a compiler ...
    (microsoft.public.vc.mfc)
  • Re: Isnt it time there was a standard align statement?
    ... C language actually allowed some portable control over data ... /* per member alignment (obviously padding before the first ... fatal with compiler specific switches - and that's no business of the ...
    (comp.lang.c)
  • Re: And the question was? (Re: Amazing, two new articles on Computerworld.com actual mention OpenVMS
    ... took alignment into consideration and included alignment instructions ... so does COBOL. ... As a member of a standards committee, it is hard for a language to ... Allowing/requiring the human to "help" the compiler produce code on some ...
    (comp.os.vms)
  • Re: And the question was? (Re: Amazing, two new articles on Computerworld.com
    ... took alignment into consideration and included alignment instructions ... As a member of a standards committee, it is hard for a language to ... actually needed alignment help somewhere else? ... Allowing/requiring the human to "help" the compiler produce code on some ...
    (comp.os.vms)
  • Re: querry related to structure padding
    ... bytes due to four byte alignment nature of compiler. ... your compiler and on every C compiler that ever existed. ... There might be padding bytes after 'B' before the start of the next ... bytes do not change the size of 'B', an array of 5 char will always ...
    (comp.lang.c)