Re: push_back problem.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Stephen Howe (sjhoweATdialDOTpipexDOTcom)
Date: 01/11/05


Date: Tue, 11 Jan 2005 08:50:12 -0000


> Nevermind I got it working now, thanks : )

Well, have you really?

"Working" should not mean, "It runs through the debugger, no run-time error
therefore it must be okay".
It is possible for the program to be in error but it works out nothing is
triggered at run-time. You get lucky.
But add or subtract a variable and at that point you become aware that
something is wrong.

A minimal set of criteria for a working program, to me, is

(i) Where you make sure that the program does not do any "undefined
behaviour" (C++ standard terminology)
and the number of "implementation defined behaviour" points in your code is
minimal.
(ii) The number of casts is minimal
(iii) The compiler does not warn on anything at the highest level
(iv) There are no logical errors
(v) const correctness is respected

For example, you had

shaderParser->Cl_InitFile((char *)realfilename.c_str());

Is the cast because Cl_InitFile() takes a char * as parameter?
Could Cl_InitFile() be altered so it takes a const char * as parameter (it
is not being change within)?
If so I would make the change. You will then find you can do

shaderParser->Cl_InitFile(realfilename.c_str());

and if you used std::string within shaderParser and passed by const
reference, you could do

shaderParser->Cl_InitFile(realfilename);

But that is design.

Stephen Howe



Relevant Pages

  • Re: declaring functions moving input pointer
    ... void consume (const char **); ...
    (comp.lang.c)
  • Re: Operator [] read or write detection
    ... You can overload the operator in a const and non-const version. ... When the assignment operator is called, ... virtual void putPHeader(const char *szKey, ...
    (microsoft.public.vc.language)
  • Re: Anders Hejlsberg comment on immutable objects
    ... >> of the class are const. ... You may not invoke this member on a const reference. ... >real contract should be enforced by both the compiler and the runtime, ... Casts are a last resort sledgehammer. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: C Pointers
    ... pointers to char", but strcmparguments are "pointers to ... The type of your strcmp arguments is (char *const). ... char * can be implicitly converted to const char *. ...
    (comp.lang.c)
  • Re: 406 Not Acceptable (was Re: "--All You Zombies--" title)
    ... Which gets promoted in expressions to const char *. ... You can, in perfectly legal, conforming code, have a non-const pointer ... not even all of the common parts. ...
    (rec.arts.sf.written)