Pelles C forum

Pelles C => General discussions => Topic started by: czerny on July 06, 2014, 04:03:19 PM

Title: wrong operator
Post by: czerny on July 06, 2014, 04:03:19 PM
Code: [Select]
printf("%u\n", 2^31);
Why is the compiler not complaining about this?
Title: Re: wrong operator
Post by: JohnF on July 06, 2014, 05:26:15 PM
I don't think the compiler is checking.

printf("%d\n", 2^44);

However, it does with this.

unsigned long long ll = 9;
printf("%d\n", ll);

John
Title: Re: wrong operator
Post by: czerny on July 06, 2014, 05:55:58 PM
Have you seen the output?
Code: [Select]
#define m1 2^32
printf("m1 : %u\n", m1);  // 34

#define m2 2^31
printf("m2 : %u\n", m2);  // 29

printf("m3 : %u\n", 2^44);  // 46
Title: Re: wrong operator
Post by: JohnF on July 06, 2014, 06:04:15 PM
I have. One assumes that without an actual type it is not checked.

And it appears that ^ is not doing the right thing.

John
 
Title: Re: wrong operator
Post by: aardvajk on July 06, 2014, 06:51:16 PM
It really is a sad sight to see two people who've presumably been using C for years not know that ^ is XOR.
pow is in math.h
Title: Re: wrong operator
Post by: JohnF on July 06, 2014, 07:42:10 PM
It really is a sad sight to see two people who've presumably been using C for years not know that ^ is XOR.
pow is in math.h

You're right!

John
Title: Re: wrong operator
Post by: czerny on July 06, 2014, 11:24:00 PM
It really is a sad sight to see two people who've presumably been using C for years not know that ^ is XOR.
pow is in math.h

You're right!

John
Hihi, thats funny! Everyone is a beginner, somehow!
Hey aardvajk, don't feel sad, laugh with us!