Menu

#57 Char constants (literals like 'a') are of type long, not int

open-later
None
3
2003-10-09
2002-01-07
No

I stumbled upon the following problem:

#define sprintf StrPrintF

A code like this:
sprintf(x, "%c", intval ? '1' : '0'); DOESN'T WORK,

while

sprintf(x, "%c", (int)(intval ? '1' : '0')); WORKS.

(where x is an initialized char*)

StrPrintF declaration is seen by the compiler before
it is used, so this behaviour is incorrect. '1' and
'0' must be automatically converted to int.

Discussion

  • Anonymous

    Anonymous - 2002-01-07
    • priority: 5 --> 7
     
  • John Marshall

    John Marshall - 2002-01-07
    • priority: 7 --> 3
    • assigned_to: nobody --> jmarshall
    • status: open --> open-later
     
  • John Marshall

    John Marshall - 2002-01-07

    Logged In: YES
    user_id=4669

    True. For now, put the cast in. This is on the list for
    fixing when we update to GCC 3.x, but I don't want to do it
    twice, which is what would happen if we did it now. See
    also
    http://www.escribe.com/computing/pcpqa/m18245.html

     
  • John Marshall

    John Marshall - 2003-10-09
    • summary: Variadic functions called incorrectly --> Char constants (literals like 'a') are of type long, not int
     

Log in to post a comment.

MongoDB Logo MongoDB