No warning for module global variable which is set but never used

webmaster webmaster@defcon-cc.org
Wed Dec 9 15:41:31 GMT 2020


I'm talking about C/C++ :-)
-------- Ursprüngliche Nachricht --------Von: Tobias Burnus <tobias@codesourcery.com> Datum: 09.12.20  13:15  (GMT+01:00) An: webmaster <webmaster@defcon-cc.org> Betreff: Re: No warning for module global variable which is set but never used The example below is for Fortran – but the same applies to C++ modulesand to static variable in general, especially if they are global variables.(It is not clear from the question about which language you were talking.)TobiasOn 09.12.20 13:13, Tobias Burnus wrote:> On 09.12.20 13:02, webmaster wrote:>>> Ahh, ok. With these explanation I understand that the compiler does>> remove it because of optimatizion. This is somehow good and bad.>> Good that unused variable does not consume any memory. Bad that>> developer is not informed that variable can be removed.>> That's the general problem with (module) global variables:>> module m>   integer :: A> end>> program main>   use m>   external foo>   A = 5>   call foo()> end>> ----------------------------> Now assume in a different file:>> subroutine foo>   use m>   print *, A> end>> In this case, the compiler cannot see while processing the first file> that 'foo' in a different file actually uses the variable - and cannot> warn.>> Doing tracking for static (implicit or explicit "SAVE") is difficult;> for (module) global variable it is impossible to do in general.>> Tobias>-----------------Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / GermanyRegistergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter


More information about the Gcc mailing list