Why the underscore

Post Reply
Posts: 69
Joined: Sat Mar 28, 2015 4:45 am
Location: Quebec - Canada

Why the underscore

Post by FredCailloux » Tue Mar 08, 2016 4:48 am

Hello Majenko,
In my previous question "re#define before or after #include" you show a piece of code example to explain some strategy to pass an object DSPI in a class.

Code: Select all

class foo {
        DSPI *_spi;
        foo(DSPI &spi) : _spi(&spi) {}
        foo(DSPI *spi) : _spi(spi) {}
        void begin() {

DSPI2 spi;
foo MyFoo(spi);
In here you show the line DSPI *_spi: Can you explain quickly why the underscore ?
Would it make a difference if the line was DSPI *spi; or DSPI *aspi; ?
Is the underscore part of the variable name or does it have a specific significance ?
Prashant Tripathi :idea: Knowing is to the Self what knowledge is to the ego

User avatar
Site Admin
Posts: 2187
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK

Re: Why the underscore

Post by majenko » Tue Mar 08, 2016 9:45 am

It's purely a convention on my part. I name my class member variables in that way so I can tell them apart from local or global variables at a glance.

Sent from my SM-T555 using Tapatalk
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

Post Reply