Writing name in C, C++

Thread Starter

anhnha

Joined Apr 19, 2012
905
Here are some definitions of class, struct and union.

Code:
class CFoo
{
   // CFoo is a CLASS defined by using 'class' keyword
};
Code:
struct SFoo
{
   // SFoo is a CLASS defined by using 'struct' keyword
};
Code:
union UFoo
{
   // UFoo is a CLASS defined by using 'union' keyword
};
As you can see, the name of "CFoo", "SFoo", "UFoo" are started by the letter "C", "S" and "U" respectively.
I guess they are short for "Class", "Struct" and "Union".
What is the purpose of writing a name like that? Is it just easy to remember?
 

nsaspook

Joined Aug 27, 2009
13,272
As you can see, the name of "CFoo", "SFoo", "UFoo" are started by the letter "C", "S" and "U" respectively.
I guess they are short for "Class", "Struct" and "Union".
What is the purpose of writing a name like that? Is it just easy to remember?
It's just a Mnemonic
You can call them any legal name in the computer language but with a large program some sort of naming convention helps you to remember the types, functions and methods.
http://en.wikipedia.org/wiki/Naming_convention_(programming)
 

vpoko

Joined Jan 5, 2012
267
It's called Hungarian notation, it's meant to remind you of the type of a variable. The reason that you're having a hard time figuring out why it's useful is because it isn't, and the practice is more commonly discouraged than encouraged.
 

nsaspook

Joined Aug 27, 2009
13,272
Some people are pretty anal about code styles in large projects. The Linux kernel is a good example, to have code accepted in the main source tree it doesn't have to follow his coding style but if you don't it's unlikely anyone one will sign-off your patch until you do.

One of the good things about an IDE like MPLABX/NetBeans is that it will auto-format code to the style of your choice.
 
Top