> As an aside, it is very good practice to re-write errors, warnings, or
> other oddities into minimal stand-alone snippets. Often you can see the
> issue yourself much more clearly than when it is buried in source code,
> and you solve the issue simply by asking the question the right way.
I don't think there's anything wrong with my code, hence the "false
positive." All other GCC warnings I coded around. I don't see anything
wrong with either of those two remaining warnings.
> I looked briefly at your "engine.cpp". The list of variable definitions
> at the start of the function tells people exactly /nothing/. Names like
> "comp", "compNext", "compThird", "var", etc., are anonymous and
> uninformative.
It requires some knowledge of what you're doing. If you look at the comp
defintion, you'll see SComp defined there. If you go to its definition
you'll see the explanation identifying what it is.
"comp" are components. A component is a part of a parsed line.
x = 5;
A component chain would consist of:
[x][whitepsace][=][whitespace][5][semicolon]
comp refers to the current component. compNext is the one after that.
And can you guess what compThird is?
I use those here and there to determine combinations of things which can
be joined together into a single component, such as with the number 999.99
being converted to [999][decimal point][99], and then being converted into
a single [number:999.99] form. I call those "natural groupings".
> That's fine for small local variables in a tight scope - just like
> using "i" as a loop variable. But good programming practice
Never use "i" for a local variable name. That's my advice. I use
something like "lnI" for [local][numeric][i].
> is to keep the scopes of such minor "helper" variables as small as
> possible.
The concept of comp, compNext, etc., is global throughout my app.
> I noticed your naming convention, and felt a shiver down my spine.
LOL! :-)
> > At the top are all of the local variables. My Visual Studio IDE has
> > a feature called "CodeView" which, when I highlight a variable, it
> > shows me where it's defined. By putting all variables at the same
> > location, when I position the flashing caret onto any of them, they
> > are all shown in that window, along with their types.
>
> Don't write bad code just to deal with limitations in your tools.
I think it's good practice. All variables are located at one place
and I don't have to go hunting (reading) line-by-line to try to find
where this one's defined, and that one's defined.
> > I categorically disagree with minimizing the scope of variables. I
> > think it's a bad idea and I do not write code that way. If I need
> > multiple variables, then I give them each unique names, and in that
> > way there is no ambiguity if the variable "i" here is the one in this
> > scope, or that scope, or the one declared over there, or the one
> > passed in as a parameter. Everything has its place. It also aids in
> > debugging because you simply have to type the name, and not try to
> > find the instance or reference of the name as the 3rd version of i
> > that's in use.
>
> You are disagreeing with mainstream standard practice, which has been
> based on a great deal of experience by a great deal of people.
If so ... then yes.
> But it's your code - no one else has to deal with it, so you can
> write it the way you want. All anyone else can do is give you
> suggestions.
It goes both ways.
> > They don't bother me. I couldn't figure out at first why I was getting
> > them and assumed there was something wrong in my code ... but as it is
> > everything works, and I don't believe there are flaws in my logic. The
> > error with regards to "var" is a particularly confusing one though. I
> > use the "var" variable in assignment as I do so I can examine it in the
> > debugger, but I don't use it other places. GCC doesn't like that.
>
> Since you still haven't said what the warning actually was, I can't
> guess why "gcc doesn't like it".
I haven't been hiding the warnings. I just don't care enough about them
being an issue to worry about it.
But, here is the output from GCC (I had to remove the line after lfHertz4
which bypasses the warning to get it to generate that warning):
C:\WINDOWS\system32\cmd.exe /c "C:/MinGW-4.8.1/bin/mingw32-make.exe -e -f Makefile"
"----------Building project:[ vjr - Release ]----------"
mingw32-make.exe[1]: Entering directory 'C:/libsf/source/vjr/vjr_mingw_gcc_codelite'
C:\MinGW-4.8.1\bin\g++.exe -c "C:/libsf/source/vjr/vjr.cpp" -O2 -Wall -Wno-comment -Wno-multichar -Wno-narrowing -Wno-write-strings -Wno-format-contains-nul -Wno-strict-aliasing -DNDEBUG -o ./Release/vjr_vjr.cpp.o -I. -I.
In file included from C:/libsf/source/vjr/vjr.h:128:0,
from C:/libsf/source/vjr/vjr.cpp:37:
C:/libsf/source/vjr/sound\sound.cpp: In function 'void iisound_generateTones(_isSSound*, u32)':
C:/libsf/source/vjr/sound\sound.cpp:369:29: warning: 'lfHertz4' may be used uninitialized in this function [-Wmaybe-uninitialized]
*lfAccum4 += lfHertz4;
^
In file included from C:/libsf/source/vjr/vjr.h:97:0,
from C:/libsf/source/vjr/vjr.cpp:37:
\libsf\utils\common\cpp\ll.cpp: In function 'bool iEngine_executeStandaloneCommand(SEdit*)':
\libsf\utils\common\cpp\ll.cpp:294:27: warning: 'var' may be used uninitialized in this function [-Wmaybe-uninitialized]
nodeFirst->prev = node; // Ignore the GCC warning message here... I don't know why it's throwing a warning. Everything here is populated and tested before use.
^
In file included from C:/libsf/source/vjr/vjr.h:125:0,
from C:/libsf/source/vjr/vjr.cpp:37:
C:/libsf/source/vjr/engine.cpp:50:14: note: 'var' was declared here
SVariable* var; // Ignore the GCC warning message here... I don't know why it's throwing a warning. var is used correctly below.
^
C:\MinGW-4.8.1\bin\g++.exe -o ../vjr.exe @"vjr.txt" -L. -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32 -lSDL
mingw32-make.exe[1]: Leaving directory 'C:/libsf/source/vjr/vjr_mingw_gcc_codelite'
0 errors, 6 warnings, total time: 00:00:27 seconds
-----
Here is the build in debug mode:
C:\WINDOWS\system32\cmd.exe /c "C:/MinGW-4.8.1/bin/mingw32-make.exe -e -f Makefile"
"----------Building project:[ vjr - Debug ]----------"
mingw32-make.exe[1]: Entering directory 'C:/libsf/source/vjr/vjr_mingw_gcc_codelite'
C:\MinGW-4.8.1\bin\g++.exe -c "C:/libsf/source/vjr/vjr.cpp" -g -O0 -Wall -Wno-comment -Wno-multichar -Wno-narrowing -Wno-write-strings -Wno-format-contains-nul -o ./Debug/vjr_vjr.cpp.o -I. -I.
C:\MinGW-4.8.1\bin\g++.exe -o ../vjr.exe @"vjr.txt" -L. -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32 -lSDL -g
mingw32-make.exe[1]: Leaving directory 'C:/libsf/source/vjr/vjr_mingw_gcc_codelite'
0 errors, 0 warnings, total time: 00:00:20 seconds