[SDL] Const correctness for SDL video

Ken Rogoway Ken at HomebrewSoftware.com
Wed Feb 14 12:25:28 PST 2007


 

If you use:

 

If ( 0 = rect.h )

 

You will get a compiler error since you cannot assign rect.h to the constant
0.

 

So this particular example is not valid.  There may be other places where
using const can help, but this is not one of them

 

- Ken

 

   _____  

From: sdl-bounces at lists.libsdl.org [mailto:sdl-bounces at lists.libsdl.org] On
Behalf Of Patrick Mohr
Sent: Wednesday, February 14, 2007 2:02 PM
To: A list for developers using the SDL library. (includes SDL-announce)
Subject: Re: [SDL] Const correctness for SDL video

 

Just for background, I usually program in c++.  By consting the input
arguments, you help reduce bugs.  The reason is because you can't
accidentally change something by accident.

Here is an example.  (I'm going to ignore const_cast since that defeats the
entire point of my example.)  If I find out that for some reason an object
is being accidentally changed, I can immediately rule out any functions that
it is passed into as const.  I'm not claiming that there are bugs that this
would help because of bugs in the SDL.  The problem is that I can't pass it
into my functions as const because those functions then need to pass into
SDL's functions.  If I had been using a const rect, I would have caught a
very annoying bug involving if( 0 = rect.h ) instead of if( 0 == rect.h ).
Also from what I understand, using const can help performance a little
because the compiler can assume that the argument won't change.  That is
just a side point thought.  Const is mostly helpful because it can help
track down bugs. 

One more example.  If I use a global variable as a color declaration, about
it accidentally being changed.  If the var is const, it won't be changed
unless I have a something like a buffer overrun.

Sorry if this post seems alittle scattered. 

On 2/14/07, Bob Pendleton <HYPERLINK
"mailto:bob at pendleton.com"bob at pendleton.com> wrote:

On Wed, 2007-02-14 at 13:17 -0500, Simon Roby wrote:
> On 2/14/07, Patrick Mohr <HYPERLINK
"mailto:kc7zzv at gmail.com"kc7zzv at gmail.com> wrote:
> > Originally my goal was to change SDL's draw functions to allow the
inputted 
> > source to be const.  I quickly found out that project would take far
more
> > knowledge than I had, but I did manage to make all of the source
rectangles
> > const.  I'm done with 1.2, but 1.3 isn't finished.  Can anyone think of
any
> > problems that would be caused by making the source rectangles const?
> > Assuming that it does compile.
>
> Won't that break binary compatibility in SDL 1.2?

I don't think that is a problem.

Just curious, why do you care enough about this to bother with doing all
this work? I teach C++ and I really don't see the point? Could you
educate me on this subject? 

                Bob Pendleton

--
+--------------------------------------+
+ Bob Pendleton: writer and programmer +
+ email: HYPERLINK "mailto:Bob at Pendleton.com"Bob at Pendleton.com             +
+ web: HYPERLINK "http://www.GameProgrammer.com"www.GameProgrammer.com
+
+ HYPERLINK "http://www.Wise2Food.com"www.Wise2Food.com                    +
+ nutrient info on 7,000+ common foods +
+--------------------------------------+ 


_______________________________________________
SDL mailing list
HYPERLINK "mailto:SDL at lists.libsdl.org"SDL at lists.libsdl.org
HYPERLINK
"http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org"http://lists.libsdl.org
/listinfo.cgi/sdl-libsdl.org 

 

--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.441 / Virus Database: 268.17.39/687 - Release Date: 2/14/2007
4:17 PM


-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.441 / Virus Database: 268.17.39/687 - Release Date: 2/14/2007
4:17 PM
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20070214/a8eee27e/attachment.html 


More information about the SDL mailing list