Pelles C forum

C language => Beginner questions => Topic started by: Yates on January 04, 2007, 12:49:35 PM

Title: prototypes with 'int c'
Post by: Yates on January 04, 2007, 12:49:35 PM
Hey,

I wonder about protos like: int fputc(int c,  FILE *stream);

The c  argument is an integer, not a char. Since there exists a separate function for widechars (fputwc) I am inclined to think that int c has nuffin to do with widechars. So where does it come from then, whats the logic?? :-s

Y.
Title: prototypes with 'int c'
Post by: Synfire on January 04, 2007, 08:31:44 PM
They use int c instead of char c for stack alignment for faster memory access to the FILE * stream argument. If they used char c then c would be 1 byte, which would misalign the next argument, and there would be a stall when they tried to access the stream argument. By converting c to an int, they pad it to the proper alignment.
Title: prototypes with 'int c'
Post by: Pelle on January 05, 2007, 08:49:33 AM
I don't have the full story, but the character input/output functions are older than the wide character input/output functions, prototypes havn't always been around, char promotes to int, the EOF value should be distinct from any character code, and so on. I guess the answer is somewhere in that area...