|
|
View previous topic :: View next topic |
Author |
Message |
akohlsmith
Joined: 25 Apr 2012 Posts: 26
|
possible to turn off "variable never used" for ext |
Posted: Fri Apr 27, 2012 11:58 pm |
|
|
I've got a project with three source files, and an include file that has the #fuses and #use lines and so on, as recommended by the manual. I also place all my externs and function prototypes in the include file.
Not all externs are used by all source files, and the compiler is throwing a warning about the unused variables.
Other compilers are smarter than this (only throwing a warning for unused variables declared in functions) and I'm wondering if something similar can be achieved with PICC? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Sat Apr 28, 2012 5:12 am |
|
|
yes, you can(should be able to) turn off any of the warnings,by adding -nnn where nnn is the number that corresponds to the 'warning' to the compiler options.
if that doesn't work, _smart_ programmers don't add unused variables in their code. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sat Apr 28, 2012 8:56 am |
|
|
Also look at #ignore_warnings on page 112 of the current CCS manual _________________ Google and Forum Search are some of your best tools!!!! |
|
|
akohlsmith
Joined: 25 Apr 2012 Posts: 26
|
|
Posted: Sat Apr 28, 2012 9:17 am |
|
|
temtronic wrote: | yes, you can(should be able to) turn off any of the warnings,by adding -nnn where nnn is the number that corresponds to the 'warning' to the compiler options. |
Thanks, but I was hoping not to disable the warning entirely, as it is a useful warning when it's not emitting false positives. I can read the manual as well as anyone, but it didn't contain the answer I was looking for.
Quote: | if that doesn't work, _smart_ programmers don't add unused variables in their code. |
Cute, but your statement would only be relevant if that's what I was doing. Smart programmers let the tools help them be better programmers, which is why I don't want to kill the warning entirely. It appears that you either didn't read my entire question or were unable to comprehend it. After reading my initial question again I see that perhaps I wasn't explicit enough, so I'll try to be a little more descriptive:
* a.c: includes foo.h, declares and uses int a, and references int c.
* b.c: includes foo.h, declares and uses int b, and references int a.
* c.c: includes foo.h, declares and uses int c, and references int a and b.
* foo.h: extern int a,b,c
PICC says b is an unused variable when compiling a.c, c is an unused variable when compiling b.c, and no warnings about c.c.
'extern' should not be triggering an unused variable warning. My reference is gcc, which even with -Wall and -pedantic does not emit unused variable warnings for global variables since it is smart enough to know that a global variable may well be referenced by other object modules in the linker. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Mon Apr 30, 2012 8:27 am |
|
|
I think you are missing a fundamental point.
CCS, is at heart a 'single pass' compiler. It now has an _option_ to link, but does not use a separate linker as such.
Now, what you are doing, is classic for a link/compiler setup, but will cause warnings with CCS, since here the compiler itself parses the extern declaration, as meaning 'this module uses this variable defined externally'. Different from a linker, where this is parsed as 'if and when you need it the declaration of this component is here'.
You can avoid the problem by writing your code with this in mind. Have each primary code component declare a #define so (for example) in a.c, have a #define BEING_COMPILED_BY_A
Then in foo.h, have the extern declarations made dependant on who is loading the code, only declaring the variables that are used in the required section.
Best Wishes |
|
|
akohlsmith
Joined: 25 Apr 2012 Posts: 26
|
|
Posted: Mon Apr 30, 2012 8:05 pm |
|
|
Ttelmah wrote: | I think you are missing a fundamental point. |
... fundamental point about CCS being a single-pass compiler snipped ...
Thank you! This is the crucial nugget I was missing!
Quote: | You can avoid the problem by writing your code with this in mind. Have each primary code component declare a #define so (for example) in a.c, have a #define BEING_COMPILED_BY_A |
Yes, this is a workaround... a damn ugly one but given the source of the issue it seems likely that it's the nicest. #include-ing header files that were just more source files made me cringe, but it looks like it's just the nature of the beast.
Thank you again. Your answer is very much appreciated. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|