Walt Mankowski on 26 Apr 2004 21:44:02 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Re: #define for 32 vs 64 bit C program?


On Mon, Apr 26, 2004 at 05:22:38PM -0400, Chip Salzenberg wrote:
> According to Walt Mankowski:
> > int main () {
> >         long i = 42;
> > #if __WORDSIZE == 64
> >         printf("i = %ld\n", i);
> > #else
> >         printf("i = %d\n", i);
> > #endif
> >         return 0;
> > }
> 
> But but but!  "%ld" is always right for long, no matter what.

Oh!  Well then...

OK, let's use a slightly more complex example, which is closer to my
actual code.  It's really C++, not C.  I'm using STL vectors, and I
want to printf their size.  (Yes, yes, I know I should be using
iostreams, but whatever.)  My code looks something like this:

  vector<double> v;
  ...
  printf("v has %d elements\n", v.size());

Looking through the STL documentation as well as the header files, it
appears that size() returns a size_type, and size_type is really a
size_t.  Is size_t guaranteed to be a long?

Walt

Attachment: signature.asc
Description: Digital signature