Jiji Gaming
Jiji Gaming

Reputation: 35

Auto Commenting code

So I have once came across a code that comments itself if the mode is not used. I don’t really remember where I saw it, but I can say it was C language. I’ll give you an example of what I remember: Assuming we have two modes Admin and user, and right now I want to use the admin mode, so the code itself will comment anything related to the user but no admin.

if (master){
...
}
//if (user) {
//...
//}

So as we can see the user was commented automatically by the compiler because it is not used. And also vice-versa if it is user mode, master code will be commented.

Do you guys have any idea what is this technique is called? And is there anywhere i can see an actual example to learn it?

Thank you so much,

Upvotes: 1

Views: 921

Answers (1)

Mike Foss
Mike Foss

Reputation: 321

As Eugene mentioned in the above comment, what you saw is likely a result of using preprocessor directives. Some IDEs will look at these (#define, #if, etc) and then change colors to indicate which code is unreachable.

Upvotes: 6

Related Questions