NO

Author Topic: prototypes with 'int c'  (Read 3328 times)

Yates

  • Guest
prototypes with 'int c'
« 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.

Synfire

  • Guest
prototypes with 'int c'
« Reply #1 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.

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2029
    • http://www.smorgasbordet.com
prototypes with 'int c'
« Reply #2 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...
/Pelle