Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C90 - C99: register struct

Tags:

c

standards

c99

c89

Is register struct legal? In terms of the standards and (independently from the standards) in GCC?

like image 395
osgx Avatar asked Jun 27 '26 21:06

osgx


2 Answers

Yes. (No citation, there is simply no prohibition on that. There is a note assuming that the use of register with arrays is valid, and arrays are far more second class citizen in C that structs).

like image 61
AProgrammer Avatar answered Jun 30 '26 13:06

AProgrammer


Yes it is legal, however since register is only a hint to the compiler to what it might try, no implementation actually has to listen to it anyway. It is also easy to make a struct that couldnt be stored within the space allotted in registers.

Once you start to get so close to machine dependant problems their part in standards tends to be merely suggestions since hardware varies such that the same things are not reliably possible at this level in all architectures.

like image 45
Fish Avatar answered Jun 30 '26 14:06

Fish