Variable declaration

Discussion to talk about software related topics only.
Post Reply
fd9750
Posts: 40
Joined: Fri Mar 29, 2013 8:08 am
Location: Belgium

Variable declaration

Post by fd9750 »

Hi,

On the assumption there is no such thing as a silly question, only silly answers here is a question the answer to which is probably very obvious but I am missing it.

in Example file "PeriodicAd.cpp" if find this:

Code: Select all

volatile edma_tcdstruct &tmrTcd = sim2.edma.tcd[DMA_CH_DTER_0 + timerNum];
It is clear what it does, how "tmrTcd" is used further on in the code and it works perfectly.

What eludes me is the exact declaration syntax: if you want to refer to a particular memory location indirectly aren't you supposed to use a pointer (e.g.: edma_tctdstruct *tmrTcd) and then use "->" instead of "." to refer to the various elements within the structure ?

I am using it and it works really well, I just can't find anything that explains the "&tmrTcd" syntax on the left hand side of the line of code.

If anyone would explain it or point to where the explanation can be found I would very much appreciate it.
dpursell
Posts: 20
Joined: Thu Aug 05, 2010 3:15 pm

Re: Variable declaration

Post by dpursell »

The ampersand (&) indicates a C++ variable type called a "reference". Without getting too into details, you can basically treat this as a pointer except you do not need to dereference the object itself it using -> or *, so you can access and modify it directly.

http://en.wikipedia.org/wiki/Reference_(C++)

-David
fd9750
Posts: 40
Joined: Fri Mar 29, 2013 8:08 am
Location: Belgium

Re: Variable declaration

Post by fd9750 »

OK, thanks for the info.
There is always something you can learn.
Post Reply