Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2002:
[Freeciv-Dev] Re: New Patch
Home

[Freeciv-Dev] Re: New Patch

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Alexander Mai <st002279@xxxxxxxxxxxxxxxxxxxxxx>
Cc: "freeciv-dev@xxxxxxxxxxx" <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] Re: New Patch
From: Ben Webb <ben@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 6 Feb 2002 17:26:29 +0000 (GMT)

On Wed, 6 Feb 2002, Alexander Mai wrote:

> On Wed, 6 Feb 2002 16:19:06 +0100, Raimar Falke wrote:
> >The original code works without warning as long as size_t isn't a
> >long. There are no information about this in the C spec. To avoid this
> >you can do a cast to int: "(int)sizeof(...)".
> 
> In turn your proposal would break if sizeof() is actually 
> of type long.

        I think "break" is a harsh word for it. Bad things would only 
happen if you can't cast to int. If you're really using structures for 
which sizeof() returns a value that doesn't fit into 32 bits, perhaps you 
should consider using smaller structures!

> My solution is perhaps not perfect, just "better" and for most
> systems it is fine. Printing size_t is a famous programming FAQ.

        Well, if you want to get picky about it, you should be casting it 
to unsigned long, given that sizeof() always returns a positive value. 
Alternatively, you could use the "%zd" format specifier on systems that 
support this.

> You don't need to teach me C programming, guys.

        Hey, I wasn't complaining about that. My only point was that your 
statement (and I quote verbatim) 'printing an int (i.e. no long) with a 
"%li" specifier' was incorrect - %li prints a long int, not an int.

        Ben
-- 
ben@xxxxxxxxxxxxxxxxxxxxxx           http://bellatrix.pcl.ox.ac.uk/~ben/
"I need a big loan from the girl zone"





[Prev in Thread] Current Thread [Next in Thread]