News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

wrong operator

Started by czerny, July 06, 2014, 04:03:19 PM

Previous topic - Next topic

czerny

printf("%u\n", 2^31);

Why is the compiler not complaining about this?

JohnF

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

czerny

Have you seen the output?

#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

JohnF

#3
I have. One assumes that without an actual type it is not checked.

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

John

aardvajk

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

JohnF

Quote from: 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

You're right!

John

czerny

#6
Quote from: JohnF on July 06, 2014, 07:42:10 PM
Quote from: 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

You're right!

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