objective c - How to use typed constants with "unused variable" warnings? -
i'm using xcode 4.6 , i've got header file includes constants utilize throughout code. don't want utilize preprocessor directives because want them typed , such.
for example, have code in 1 of .h files:
static nsstring *kerrorcannotdividebyzero = @"error: cannot split zero"; and utilize in corresponding .m file:
[self showtoast:kerrorcannotdividebyzero]; i warning:
/path/to/my/headerfile.h:32:18: unused variable 'kerrorcannotdividebyzero' i know it's warning, i've got 50 of these warnings clogging compiler output.
why getting warning , how resolve it?
i'm not interested in suppressing unused variable warnings, because want legit ones.
make declaration in header extern rather static. you're doing creating variable every translation unit includes header, , why clang warning you, because legitimately defined variable not beingness used. extern keyword tells compiler definition of variable found somewhere else (it might in same translation unit or might in another).
in header, have:
// declare constant exists somewhere extern nsstring * const kerrorcannotdividebyzero; and in one of .m files (typically 1 shares same name header), put
// define constant, i.e. exists nsstring * const kerrorcannotdividebyzero = @"error: cannot split zero"; declaring variables extern allows compiler ensure treating variable correctly if doesn't know defined (e.g. can't utilize nsarray). linker has job of making sure defined somewhere.
objective-c c xcode
No comments:
Post a Comment