Re: Regular expression question

Mat Sutcliffe <[email protected]>
Newsgroups gmane.comp.graphics.crystalspace.devel
Message-ID <CACE5BzJZwUYL+N3ZWPQy2w9+MoXztzrxWb1+E1FWz_aFMBiTbQ@mail.gmail.com>
On 19 August 2012 14:40, Andrei Bârsan <[email protected]> wrote:

> Should I just be careful and cast to an unsigned int and
> use %u from now on?
>

That will work fine in nearly all cases. It might be a problem only if
size_t is wider than unsigned int and the value you are printing is greater
than UINT_MAX. You can assume UINT_MAX is at least 4 billion wherever CS is
supported, so it's only a problem for very big values. If you are worried
about bigger values (e.g. you have an array bigger than 4 gigabytes), you
can cast to long long unsigned int and use %llu. That'll give you at least
18 billion billion (18 million terabytes).

The "proper" way, though, is something like this:

#ifdef CS_COMPILER_MSVC
  #define PRINTF_FMT_SIZE_T "%Iu"
#else
  #define PRINTF_FMT_SIZE_T "%zu"
#endif
...
size_t foo = 123;
printf("This is a size_t: " PRINTF_FMT_SIZE_T "\n", foo);

It's completely up to you whether you want to go with casting or
preprocessor macros. Casting will work unless you are doing something
really exotic.

And if this is just experimental code that only needs to work on one
compiler, just use %Iu for MSVC and %zu for any other compiler, and you
don't need a cast or a macro.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

_______________________________________________
Crystal-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/crystal-develop
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.