NO

Author Topic: wrong operator  (Read 3540 times)

czerny

  • Guest
wrong operator
« on: July 06, 2014, 04:03:19 PM »
Code: [Select]
printf("%u\n", 2^31);
Why is the compiler not complaining about this?

JohnF

  • Guest
Re: wrong operator
« Reply #1 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
« Last Edit: July 06, 2014, 05:30:22 PM by JohnF »

czerny

  • Guest
Re: wrong operator
« Reply #2 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

JohnF

  • Guest
Re: wrong operator
« Reply #3 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
 
« Last Edit: July 06, 2014, 06:14:34 PM by JohnF »

aardvajk

  • Guest
Re: wrong operator
« Reply #4 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

JohnF

  • Guest
Re: wrong operator
« Reply #5 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

czerny

  • Guest
Re: wrong operator
« Reply #6 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!
« Last Edit: July 06, 2014, 11:26:38 PM by czerny »