public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* unsigned long long int with os-x
@ 2002-10-13  7:59 Nicholas Strauss
  2002-10-13 17:06 ` Segher Boessenkool
  0 siblings, 1 reply; 3+ messages in thread
From: Nicholas Strauss @ 2002-10-13  7:59 UTC (permalink / raw)
  To: gcc-help; +Cc: Nicholas Strauss

[-- Attachment #1: Type: text/plain, Size: 361 bytes --]

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;
   printf("u: %ld uu: %ld\n", u, u-1);
   printf("maxint %ld\n", INT64_MAX);
}

What compiler/linker options should I use with gcc?
What format should I use with printf?

Nick
infinity software

[-- Attachment #2: Type: text/enriched, Size: 461 bytes --]

Hi,


I'm trying to use gcc in darwin os-x. I've written the following piece
of code:

<fontfamily><param>Times New Roman</param><bigger><bigger>

int main(int argc, char *argv[])

{

  unsigned long long int   u;


  u = 1<<<<63;

  printf("u: %ld uu: %ld\n", u, u-1);

  printf("maxint %ld\n", INT64_MAX);

}


What compiler/linker options should I use with gcc? 

What format should I use with printf?


Nick

infinity software</bigger></bigger></fontfamily>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: unsigned long long int with os-x
  2002-10-13  7:59 unsigned long long int with os-x Nicholas Strauss
@ 2002-10-13 17:06 ` Segher Boessenkool
  2002-10-13 17:11   ` Nicholas Strauss
  0 siblings, 1 reply; 3+ messages in thread
From: Segher Boessenkool @ 2002-10-13 17:06 UTC (permalink / raw)
  To: Nicholas Strauss; +Cc: gcc-help, Nicholas Strauss

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: unsigned long long int with os-x
  2002-10-13 17:06 ` Segher Boessenkool
@ 2002-10-13 17:11   ` Nicholas Strauss
  0 siblings, 0 replies; 3+ messages in thread
From: Nicholas Strauss @ 2002-10-13 17:11 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: gcc-help, Nicholas Strauss

Hi Segher,
Yes, this works on Macintosh OS-X.
u: 9223372036854775808
u--: 9223372036854775807
u++: 9223372036854775809
2u: 0
thanks,
Nick
On Sunday, October 13, 2002, at 08:04 PM, Segher Boessenkool wrote:

> 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
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-10-14  0:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-13  7:59 unsigned long long int with os-x Nicholas Strauss
2002-10-13 17:06 ` Segher Boessenkool
2002-10-13 17:11   ` Nicholas Strauss

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).