C language > Beginner questions

prototypes with 'int c'

(1/1)

Yates:
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.

Synfire:
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.

Pelle:
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...

Navigation

[0] Message Index

Go to full version