Forums

Pointers on pointers (ha...ha...ha..)

Started by Unknown January 3, 2008
Hi

New to all this DSP stuff but I'm programming the TI DM642 in C.
Looking at some sample sourcecode for a similar task from someone who
knows a lot about DSP, I've noticed that they've not used pointers or
passed anything between procedures and relied on global variables.
I'd always been taught global variables are the most sinful thing a
coder can do but wondered if there was some reason this was done for a
DSP?

Cheers...

pulse_web@hotmail.com wrote:

> New to all this DSP stuff but I'm programming the TI DM642 in C. > Looking at some sample sourcecode for a similar task from someone who > knows a lot about DSP, I've noticed that they've not used pointers or > passed anything between procedures and relied on global variables. > I'd always been taught global variables are the most sinful thing a > coder can do but wondered if there was some reason this was done for a > DSP?
It is well known that the elephant riders or the rice farmers can't tolerate the inconvenience of not been able to access a variable directly. The most advanced of them (who can tell a mouse from keyboard) are using the "efficiency of the code" as an excuse. VLV
pulse_web@hotmail.com wrote:
> Hi > > New to all this DSP stuff but I'm programming the TI DM642 in C. > Looking at some sample sourcecode for a similar task from someone who > knows a lot about DSP, I've noticed that they've not used pointers or > passed anything between procedures and relied on global variables. > I'd always been taught global variables are the most sinful thing a > coder can do but wondered if there was some reason this was done for a > DSP? > > Cheers...
I can't think of a good reason. Globals remain sinful in my book. -- Jim Thomas Principal Applications Engineer Bittware, Inc jthomas@bittware.com http://www.bittware.com (603) 226-0404 x536 Today is the last day of your life so far.
Jim Thomas wrote:
> pulse_web@hotmail.com wrote: >> Hi >> >> New to all this DSP stuff but I'm programming the TI DM642 in C. >> Looking at some sample sourcecode for a similar task from someone who >> knows a lot about DSP, I've noticed that they've not used pointers or >> passed anything between procedures and relied on global variables. >> I'd always been taught global variables are the most sinful thing a >> coder can do but wondered if there was some reason this was done for a >> DSP? >> >> Cheers... > > I can't think of a good reason. Globals remain sinful in my book.
It's funny how this myth gets propogated. So you never use globals? (I don't believe this). I can understand that these days, what with OS's and canned IO libs and wotnot, most programmers can (and evidently do) delude themselves about this, but I wouldn't have thought comp.dsp folk lead such sheltered lives :-) Regards -- Adrian Hey
On Thu, 03 Jan 2008 21:37:48 +0000, Adrian Hey wrote:

> Jim Thomas wrote: >> pulse_web@hotmail.com wrote: >>> Hi >>> >>> New to all this DSP stuff but I'm programming the TI DM642 in C. >>> Looking at some sample sourcecode for a similar task from someone who >>> knows a lot about DSP, I've noticed that they've not used pointers or >>> passed anything between procedures and relied on global variables. I'd >>> always been taught global variables are the most sinful thing a coder >>> can do but wondered if there was some reason this was done for a DSP? >>> >>> Cheers... >> >> I can't think of a good reason. Globals remain sinful in my book. > > It's funny how this myth gets propogated. So you never use globals? (I > don't believe this). I can understand that these days, what with OS's > and canned IO libs and wotnot, most programmers can (and evidently do) > delude themselves about this, but I wouldn't have thought comp.dsp folk > lead such sheltered lives :-) > > Regards
Globals are, IMHO, best when used very sparingly, but as you say you can't get rid of them. -- Tim Wescott Control systems and communications consulting http://www.wescottdesign.com Need to learn how to apply control theory in your embedded system? "Applied Control Theory for Embedded Systems" by Tim Wescott Elsevier/Newnes, http://www.wescottdesign.com/actfes/actfes.html
On Thu, 03 Jan 2008 06:38:29 -0800, pulse_web wrote:

> Hi > > New to all this DSP stuff but I'm programming the TI DM642 in C. Looking > at some sample sourcecode for a similar task from someone who knows a > lot about DSP, I've noticed that they've not used pointers or passed > anything between procedures and relied on global variables. I'd always > been taught global variables are the most sinful thing a coder can do > but wondered if there was some reason this was done for a DSP? > > Cheers...
Using globals instead of pointers means that the addresses of the data is known at link time, which saves a level of indirection, which speeds things up slightly. If the _only_ thing you care about is speed of execution, then using globals everywhere is appropriate. If you can stand to lose a few clock ticks to indirection it is much easier to write portable, reusable code by passing data in the function call. -- Tim Wescott Control systems and communications consulting http://www.wescottdesign.com Need to learn how to apply control theory in your embedded system? "Applied Control Theory for Embedded Systems" by Tim Wescott Elsevier/Newnes, http://www.wescottdesign.com/actfes/actfes.html
>Jim Thomas wrote: >> pulse_web@hotmail.com wrote: >>> Hi >>> >>> New to all this DSP stuff but I'm programming the TI DM642 in C. >>> Looking at some sample sourcecode for a similar task from someone who >>> knows a lot about DSP, I've noticed that they've not used pointers or >>> passed anything between procedures and relied on global variables. >>> I'd always been taught global variables are the most sinful thing a >>> coder can do but wondered if there was some reason this was done for
a
>>> DSP? >>> >>> Cheers... >> >> I can't think of a good reason. Globals remain sinful in my book. > >It's funny how this myth gets propogated. So you never use globals? >(I don't believe this). I can understand that these days, what with >OS's and canned IO libs and wotnot, most programmers can (and evidently >do) delude themselves about this, but I wouldn't have thought comp.dsp >folk lead such sheltered lives :-) > >Regards >-- >Adrian Hey >
Globals cannot be bad in all situations. Who wants to pass pointers all throught a chain of 100 functions? That is the concern for optimization. ( arguments passing may use stack. perhaps the original variable is also on stack because it is local to caller function).In a "run to completion" module globals may help. Better have a list where you cannot use a global. a reentrant function ( not run to completion ) is one example perhaps.
"Tim Wescott" <tim@seemywebsite.com> wrote in message
news:KaqdnY-9k7RCXeDanZ2dnUVZ_tjinZ2d@web-ster.com...

> Globals are, IMHO, best when used very sparingly, but as you say you > can't get rid of them.
You mean passing the data between the threads? This could be done by messaging, although it could be too heavy solution. Vladimir Vassilevsky DSP and Mixed Signal Consultant www.abvolt.com
Tim Wescott wrote:
> Using globals instead of pointers means that the addresses of the data is > known at link time, which saves a level of indirection, which speeds > things up slightly. > > If the _only_ thing you care about is speed of execution, then using > globals everywhere is appropriate. If you can stand to lose a few clock > ticks to indirection it is much easier to write portable, reusable code > by passing data in the function call.
More importantly IMO, there are many situations where the use of top level (aka "global") variables is absolutely the "Right Thing To Do" (TM) for semantic and safety reasons. They provide important uniqueness guarantees. Of course such situations are generally hidden from typical apps level programmers by well abstracted IO interfaces. So well hidden in fact that many seem completely unaware of how the OS's or language RTS's or IO libs or GUI "frameworks" (or whatever) that they are dependent on *actually work*. But someone has to implement these at the end of the day. Maybe those who believe "global variables" are the root of all evil should stop to ponder how malloc really works, or what really happens when they open a socket, or how an interrupt handler really works (for example). Umm.. Regards -- Adrian Hey
On Thu, 03 Jan 2008 10:08:35 -0500, Jim Thomas <jthomas@bittware.com>
wrote:

>pulse_web@hotmail.com wrote: >> Hi >> >> New to all this DSP stuff but I'm programming the TI DM642 in C. >> Looking at some sample sourcecode for a similar task from someone who >> knows a lot about DSP, I've noticed that they've not used pointers or >> passed anything between procedures and relied on global variables. >> I'd always been taught global variables are the most sinful thing a >> coder can do but wondered if there was some reason this was done for a >> DSP? >> >> Cheers... > >I can't think of a good reason. Globals remain sinful in my book.
Shucks, I ain't got nuttin' but globals when I design my hardware. I leave all that fancy indirect stuff to the software folk. I leave the bugs to them as well. Allan