g++ - gcc warnings: defined but not used vs unused variable -


whenever compile code observe following 2 warnings:

warning: '<variable>' defined not used warning: unused variable '<variable>' 

i tried google did not find helpful thread or blog difference between these 2 warnings.

example sample code snippet me or if duplicating existing thread please feel free refer.

i think difference kind of subtle here code snippet along compiler output demonstrates differences:

#include <iostream>  static const char * hello = "hello";  void foo() {     int i;      std::cout << "foo" << std::endl; } ... argenet@martell ~ % g++ /tmp/def_not_used.cpp -wall /tmp/def_not_used.cpp: in function ‘void foo()’: /tmp/def_not_used.cpp:6:9: warning: unused variable ‘i’ [-wunused-variable]      int i;          ^ /tmp/def_not_used.cpp: @ global scope: /tmp/def_not_used.cpp:3:21: warning: ‘hello’ defined not used [-wunused-variable]  static const char * hello = "hello"; 

so here local variable never used therefore compiler may omit while generating code , emits "unused variable" warning.

at same time, static c-style literal cannot emitted available wider scope (the whole .cpp file). however, not referenced code in module compiler warns "defined not used".


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -