Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#define: why uppercase?

When defining a macro (e.g. #define BALL). Why do people use uppercase letters? I can write something like #define ball. It is not in uppercase, but it works.

like image 834
nicael Avatar asked Nov 28 '13 15:11

nicael


2 Answers

It's convention. It makes reading and understanding code easier. It's not required, but recommended.

like image 71
Fiddling Bits Avatar answered Sep 29 '22 06:09

Fiddling Bits


Why do you use _ for long variable names ? And why don't you just name variables as a or b because It is easy to understand and debug.

Using a variable name such as TotalHeight makes more sense than simple i. Some people even prefix the data type such as Int_TotalHeight. Its easy to maintain the code.

To answer your question, people use it for more understanding. Usually

1)To differentiate the variable name and macro name

 #define MAX 45 // easy to understand, it is a macro
 int max=45;

2)To differentiate the function from a macro. Say

 #define MULT(x, y) (x) * (y) 
 int mult(int,int);
like image 33
niko Avatar answered Sep 29 '22 08:09

niko