468,463 Members | 1,957 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,463 developers. It's quick & easy.

size_t literals?


Hi!

On a machine where size_t is 64-bit, unsigned long is 32-bit, how
does one construct a size_t literal that says 2^32? Typing in

size_t x = 4294967296UL;

complains about the value being too large for unsigned long
(obviously, it's too large by one).

The nonstandard suffices "UI64" are also not recognized by the
compiler.

Should I construct with a value of 4294967295UL and then increment
the size_t variable?

TIA,
- J.
Feb 28 '08
50 9762
On 2 mar, 22:52, Micah Cowan <mi...@micah.cowan.namewrote:
Ioannis Vranos <ivra...@nospam.no.spamfreemail.grwrites:
James Kanze wrote:
This is, of course, an incompatibility with C, since C allows
unsigned long even for a decimal.
I did not understand your last sentence above.
He means that a decimal literal without one of the suffixes, that
specifies a number greater than LONG_MAX is undefined in C++ (which
requires it to be representable as a long), but not in C (incuding
C90), which allows (requires) it to be represented as an unsigned
long.
Exactly, although when I reread the sentence I actually wrote,
it's not surprising the Ioannis didn't understand it.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Mar 3 '08 #51

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by nico | last post: by
17 posts views Thread by Janice | last post: by
reply views Thread by Robin Tucker | last post: by
6 posts views Thread by copx | last post: by
4 posts views Thread by Tyler Durden | last post: by
15 posts views Thread by George Sakkis | last post: by
5 posts views Thread by bradeck | last post: by
27 posts views Thread by SasQ | last post: by
25 posts views Thread by Lennart Benschop | last post: by
7 posts views Thread by lithiumcat | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kmladenovski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.