• AVR Freaks

Hot!XC8 v2.05 C99 compiler error

Page: < 123 Showing page 3 of 3
Author
mouchuanlin
Starting Member
  • Total Posts : 56
  • Reward points : 0
  • Joined: 2019/01/23 12:41:10
  • Location: 0
  • Status: offline
Re: XC8 v2.05 C99 compiler error 2019/09/09 13:56:39 (permalink)
0
My guess those functions are not working too. I am wondering what test did Microchip do before release.
 
#define isalpha(a) (0 ? isalpha(a) : (((unsigned)(a)|32)-'a') < 26)
#define isdigit(a) (0 ? isdigit(a) : ((unsigned)(a)-'0') < 10)
#define islower(a) (0 ? islower(a) : ((unsigned)(a)-'a') < 26)
#define isupper(a) (0 ? isupper(a) : ((unsigned)(a)-'A') < 26)
#define isprint(a) (0 ? isprint(a) : ((unsigned)(a)-0x20) < 0x5f)
#define isgraph(a) (0 ? isgraph(a) : ((unsigned)(a)-0x21) < 0x5e)
#define isspace(a) (0 ? isspace(a) : ((a == ' ') || ((unsigned)(a)-'\t' < 5)))
#41
jtemples
عُضْوٌ جَدِيد
  • Total Posts : 11524
  • Reward points : 0
  • Joined: 2004/02/13 12:31:19
  • Location: Southern California
  • Status: offline
Re: XC8 v2.05 C99 compiler error 2019/09/09 15:15:48 (permalink)
0
You'll need to open a support ticket.
#42
ric
Super Member
  • Total Posts : 25215
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: XC8 v2.05 C99 compiler error 2019/09/09 15:40:48 (permalink)
0
Is this some new attempt to make sure the macro is treated as a single block, similar to the do/while construct many have used in the past?
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#43
1and0
Access is Denied
  • Total Posts : 10223
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: XC8 v2.05 C99 compiler error 2019/09/09 16:21:08 (permalink)
0
#44
mbrowning
USNA79
  • Total Posts : 1583
  • Reward points : 0
  • Joined: 2005/03/16 14:32:56
  • Location: Melbourne, FL
  • Status: offline
Re: XC8 v2.05 C99 compiler error 2019/09/09 16:37:31 (permalink)
+2 (2)
mouchuanlin
My guess those functions are not working too.

Why do you say they aren’t working? The macros override the functions in such a way that a warning is generated, but they should still work. You can ignore warnings when you know what causes them
#45
1and0
Access is Denied
  • Total Posts : 10223
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: XC8 v2.05 C99 compiler error 2019/09/09 18:06:17 (permalink)
+1 (1)
I found the reason. ;)  https://embeddedartistry.com/blog/tag/Optimization
 
Quoted here:
Phillip Johnston
April 12, 2017
Neat trick: Flexible Macro Vs Function Definitions
Phillip Johnston
 
I was looking over musl's ctype.h header while working on libc earlier today. In the header, I noticed a curious set of definitions:
#define isalpha(a) (0 ? isalpha(a) : (((unsigned)(a)|32)-'a') < 26)
#define isdigit(a) (0 ? isdigit(a) : ((unsigned)(a)-'0') < 10)
#define islower(a) (0 ? islower(a) : ((unsigned)(a)-'a') < 26)
#define isupper(a) (0 ? isupper(a) : ((unsigned)(a)-'A') < 26)
#define isprint(a) (0 ? isprint(a) : ((unsigned)(a)-0x20) < 0x5f)
#define isgraph(a) (0 ? isgraph(a) : ((unsigned)(a)-0x21) < 0x5e)

It took me a few moments to figure out what was going on. Notice the conditional block that is used:
(0 ? isalpha(a) : (((unsigned)(a)|32)-'a') < 26)

Since 0 is the predicate for the if statement, the "inline" version of the isalpha macro will be used instead of the function call. If you want to use the function, you simply convert the 0 to 1. This is a clever way of controlling the behavior of code which could be either inline or a function call.
 
But why do we care about selecting between the two versions in the first place?
 
If you are re-using specific lines of code repeatedly (e.g. functions implemented as macros), the code is re-added for every invocation of the macro. This means that you have multiple copies of that particular code in multiple locations, increasing your overall binary size due to duplicate code.
 
The binary size increase may be worth it for any number of reasons. However, in many constrained embedded environments this binary size bloat is not desirable. Functions provide a reduction in code storage (you just need the one copy), but they do incur overhead penalties.
 
Optimizing for speed and binary size can be tricky. If you find yourself in a situation where you need to compare macro-vs-functions, this may be a helpful paradigm.
 
Happy hacking!

#46
Page: < 123 Showing page 3 of 3
Jump to:
© 2020 APG vNext Commercial Version 4.5