[SDL] Const correctness for SDL video

Patrick Mohr kc7zzv at gmail.com
Wed Feb 14 12:01:44 PST 2007


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 <bob at pendleton.com> wrote:
>
> On Wed, 2007-02-14 at 13:17 -0500, Simon Roby wrote:
> > On 2/14/07, Patrick Mohr <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: Bob at Pendleton.com             +
> + web: www.GameProgrammer.com          +
> + www.Wise2Food.com                    +
> + nutrient info on 7,000+ common foods +
> +--------------------------------------+
>
>
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20070214/854d87dc/attachment-0001.html 


More information about the SDL mailing list