This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: unsigned long long int with os-x
- From: Segher Boessenkool <segher at koffie dot nl>
- To: Nicholas Strauss <nicks at carriage dot chesco dot com>
- Cc: gcc-help at gcc dot gnu dot org, Nicholas Strauss <ncs at alum dot mit dot edu>
- Date: Mon, 14 Oct 2002 02:04:42 +0200
- Subject: Re: unsigned long long int with os-x
- References: <9E647882-DEBB-11D6-BFB0-000393AC01F6@carriage.chesco.com>
Nicholas Strauss wrote:
>
> Hi,
>
> I'm trying to use gcc in darwin os-x. I've written the following piece of code:
>
> int main(int argc, char *argv[])
> {
> unsigned long long int u;
>
> u = 1<<63;
This is the int 1 shifted by 63 bits to the left; that's "undefined behaviour"
by the C standard (and will probably result in 0).
Write
u = 1LL << 63;
instead.
> printf("u: %ld uu: %ld\n", u, u-1);
> printf("maxint %ld\n", INT64_MAX);
> }
>
> What compiler/linker options should I use with gcc?
No special options are needed. But try out -Wall and -W.
> What format should I use with printf?
"%lld" if I remember correctly.
Have fun,
Segher