• AVR Freaks

Hot!32 Bit multiplication with PIC

Page: < 12 Showing page 2 of 2
Author
1and0
Access is Denied
  • Total Posts : 9994
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: 32 Bit multiplication with PIC 2019/10/20 17:39:41 (permalink)
0
jtemples
All decimal constants are signed.

In C90, an unsuffixed decimal constant can be "unsigned long".

That brings me to this question. In C99, is the unsuffixed decimal literal  18446744073709551615  an "unsigned long long" or it's out of range?
 
#21
jtemples
عُضْوٌ جَدِيد
  • Total Posts : 11426
  • Reward points : 0
  • Joined: 2004/02/13 12:31:19
  • Location: Southern California
  • Status: offline
Re: 32 Bit multiplication with PIC 2019/10/20 18:24:19 (permalink)
+1 (1)
Unsuffixed decimal constants are never unsigned in C99.  The special case in C90 that allowed that was removed in C99.
#22
1and0
Access is Denied
  • Total Posts : 9994
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: 32 Bit multiplication with PIC 2019/10/20 19:36:59 (permalink)
0
XC8 v2 in C99 mode gives this warning:
 
warning: integer literal is too large to be represented in a signed integer type, interpreting as unsigned [-Wimplicitly-unsigned-literal]
#23
jtemples
عُضْوٌ جَدِيد
  • Total Posts : 11426
  • Reward points : 0
  • Joined: 2004/02/13 12:31:19
  • Location: Southern California
  • Status: offline
Re: 32 Bit multiplication with PIC 2019/10/20 20:07:37 (permalink)
0
I don't know if XC8 C99 has a "pedantic" mode like gcc does, but this is what gcc -pedantic-errors -std=c99 gives:
error: integer constant is so large that it is unsigned
18446744073709551615;
Without -pedantic-errors, it just gives a warning similar to XC8.
#24
JPortici
Super Member
  • Total Posts : 850
  • Reward points : 0
  • Joined: 2012/11/17 06:27:45
  • Location: Grappaland
  • Status: online
Re: 32 Bit multiplication with PIC 2019/10/20 22:55:49 (permalink)
0
jtemples
I don't know if XC8 C99 has a "pedantic" mode like gcc does

 
Yes, there is: you have to set warning levels at the minimum level possible and enable the treat warning as errors option. Annoying because it throws all the (752) warnings
 
Annoying like you have to cast every single array index, let it be literal or variable
 
-mwarn=level (from -9 to 9)
-Wpedantic (which will warning that the c library may throw errors)
 
no option to treat warnings as errors though
 
post edited by JPortici - 2019/10/21 00:42:27
#25
NorthGuy
Super Member
  • Total Posts : 5810
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: offline
Re: 32 Bit multiplication with PIC 2019/10/21 07:42:48 (permalink)
+1 (1)
1and0
In C99, is the unsuffixed decimal literal  18446744073709551615  an "unsigned long long" or it's out of range?



"If an integer constant cannot be represented by any type in its list and has no extended integer type, then the integer constant has no type." (C99 - 6.4.4.1.6)
 
#26
LostInSpace
Super Member
  • Total Posts : 276
  • Reward points : 0
  • Joined: 2016/03/11 22:47:59
  • Location: 0
  • Status: offline
Re: 32 Bit multiplication with PIC 2019/10/21 09:14:44 (permalink)
+1 (1)
Ric is of course correct, unfortunately you don't know which 'assumptions to adjust' until one of them jumps up and bites you.   ;-)
 
#27
Page: < 12 Showing page 2 of 2
Jump to:
© 2019 APG vNext Commercial Version 4.5