29 Apr, 2009, David Haley wrote in the 21st comment:
Votes: 0
I think you said what Elanthis said :tongue:
Quote
Learning about structure padding and alignment pretty much removed my desire to use the smallest type possible.

Well, using a small type still helps with structure padding. If you pad to every 4 bytes, and only need 0-255, then using 4 chars is much more memory efficient than using 4 ints. Yes, you still need to worry about the fetching and masking, but really, the masking is a trivial operation anyhow, and in the meantime you've reduced storage by four times (assuming 4-byte ints). (Everybody needs to fetch, so it's a common penalty.)
29 Apr, 2009, boblinski wrote in the 22nd comment:
Votes: 0
Tyche said:
fprintf (fp, "Mobs %4d (%8d bytes), %2d free (%d bytes)\n",
count, count * int(sizeof (*fch)), count2,
count2 * int(sizeof (*fch)));

I like my idea above even better. ;-)


I changed my code to look like that, however now I get the following error for that section of code:
Quote
db.c:3367: error: parse error before "int"
29 Apr, 2009, Kline wrote in the 23rd comment:
Votes: 0
fprintf (fp, "Mobs    %4d (%8d bytes), %2d free (%d bytes)\n", 
count, count * (int)sizeof (*fch), count2,
count2 * (int)sizeof (*fch));


Corrected. While not as clean as just editing your type specifiers, that should work.
29 Apr, 2009, boblinski wrote in the 24th comment:
Votes: 0
Alright, this is just getting annoying..

This is what I have:
fprintf (fp, "Mobs    %4d (%8u bytes), %2d free (%u bytes)\n",
count, count * (sizeof (*fch)), count2,
count2 * (sizeof (*fch))); /*line 3368*/


When compiling in Cygwin, I have no issues.. however- when compiling on the server using Putty I get this warning:
Quote
db.c:3368: warning: format '%8u' expects type 'unsigned int', but argument 4 has type 'long unsigned int'
db.c:3368: warning: format '%u' expects type 'unsigned int', but argument 6 has type 'long unsigned int'


BUT..

If I change the code to look like:
fprintf (fp, "Mobs    %4d (%8lu bytes), %2d free (%lu bytes)\n",
count, count * (sizeof (*fch)), count2,
count2 * (sizeof (*fch))); /*line 3368*/


Then I get no problems compiling on Putty- however when using Cygwin I get this warning:
Quote
db.c:3368: warning: long unsigned int format, unsigned int arg (arg 4)
db.c:3368: warning: long unsigned int format, unsigned int arg (arg 6)
db.c:3368: warning: long unsigned int format, unsigned int arg (arg 4)
db.c:3368: warning: long unsigned int format, unsigned int arg (arg 6)
29 Apr, 2009, Davion wrote in the 25th comment:
Votes: 0
Wow. That is just mind boggling :P. Have you tried casting, like Tyche suggested? I honestly don't know why you're getting those warnings. When I was working with the very same code and compiling between 64bit and 32bit, I'd simply switch between %ld, and %d for 64bit and 32bit respectively. I think this may call for some down, and dirty, manual casting. Just to force this bugger to bow to your whim ;).
30 Apr, 2009, Tyche wrote in the 26th comment:
Votes: 0
puTTY is a Telnet client. It don't compile anything. In fact, I often use puTTY to login to a cygwin bash shell.

'uname' and 'gcc –version' provide more useful information in solving problems.

For example on one of my cycgwin shells…
$ uname -srm
CYGWIN_NT-6.0 1.5.25(0.156/4/2) i686
$ gcc –version
gcc (GCC) 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)

And on one of Unix systems…
$ uname -srm
Linux 2.6.25-gentoo-r7 x86_64
$ gcc –version
gcc (GCC) 4.1.2 (Gentoo 4.1.2 p1.0.2)
30 Apr, 2009, Tyche wrote in the 27th comment:
Votes: 0
Kline said:
fprintf (fp, "Mobs    %4d (%8d bytes), %2d free (%d bytes)\n", 
count, count * (int)sizeof (*fch), count2,
count2 * (int)sizeof (*fch));


Corrected. While not as clean as just editing your type specifiers, that should work.


Whoops. Yes.
The problem is size_t changes with compiler version. Manually casting "fixes" that.
And by "fix" I mean it's one way to tell the compiler to STFU.
Of course I would not be surprised if C compilers start bleating about manual casting.
Turn off the warnings (or just ignore them and laugh) is yet another way to put the compiler in its place. ;-)
30 Apr, 2009, elanthis wrote in the 28th comment:
Votes: 0
Doh, I'm dumb. Use the C99 %z specifier for size_t types. GCC supports it in non-strict C89 mode as well.
20.0/28