Q: How can I pass constant values to functions which accept structure arguments? How can I create nameless, immediate, constant structure values?
A: Traditional C had no way of generating anonymous structure values; you had to use a temporary structure variable or a little structure-building function; see question 14.11 for an example.
C99 introduces ``compound literals'', one form of which provides for structure constants. For example, to pass a constant coordinate pair to a hypothetical plotpoint function which expects a struct point, you can call
plotpoint((struct point){1, 2});Combined with ``designated initializers'' (another C99 feature), it is also possible to specify member values by name:
plotpoint((struct point){.x=1, .y=2});
See also question 4.10.
References:
C9X Sec. 6.3.2.5, Sec. 6.5.8