Mark M. Hoffman on 26 Apr 2004 22:45:05 -0000


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

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


Hi Walt:

* Walt Mankowski <waltman@pobox.com> [2004-04-26 17:43:41 -0400]:
> 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?

No, but I don't see how it could be larger than long.  Plauger writes
about size_t: "Almost certainly it is either unsigned int or unsigned
long."

The standard *does* guarantee that size_t is unsigned; so... "%lu".

As you mentioned... if you use iostreams, you don't have to worry about it.

Regards,

-- 
Mark M. Hoffman
mhoffman@lightlink.com

___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug