Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C 

Include Guards Names

Hello everyone.
I need some help on understanding how include guard names work. I know that C is case-sensitive so every name is different from another. I've seen that when people define their own header files, they put include guards that are always the name of their header in capital letters.
Let's say i have a header file called mytest.h which has some code in it, for example:

Code
#ifndef MYTEST_H
#define MYTEST_H

/* declerations
   go
   here
*/
#endif /* MYTEST_H */

What will happen if i rename my file from mytest.h --> Mytest.h or MyTeSt.h (generally something different). And let's say if i indeed rename my file to Mytest.h, then the new guards will still be the same as before or something else?
Nothing will happen, in fact those definitions do not have any real connection with the filename. Its just common sense.
You do not need anymore header guards since they are somewhat archaic. You can simply use #pragma once, which is a widely supported standard to do the same thing as header guards.

https://en.wikipedia.org/wiki/Pragma_once
The wikipedia link says #pragma once is not standard.
(Mar 5, 2018 09:57 PM)Mouse❤️ Wrote:  The wikipedia link says #pragma once is not standard.

You are absolutely correct, Mouse❤️.

It's discussed here in more depth (C++11):
- https://stackoverflow.com/questions/2369...1-standard

It is inarguably non-standard, but is widely accepted by nearly every modern compiler in 2018.
Is there any such thing as a woman of honor, and sincerity?

https://www.PutItOnMute.com/

4K HDR, WDR time-lapsed truck driving videos!
(Mar 5, 2018 09:57 PM)Mouse❤️ Wrote:  The wikipedia link says #pragma once is not standard.

Yes, it is not standard, but all but one of the compilers on that page supports it, hence my word choice of widely supported instead of "is the new standard."
I'm aware. It's supported, I'm just correcting what you said because you said it is "a widely accepted standard"
(Mar 6, 2018 08:32 PM)Mouse❤️ Wrote:  I'm aware. It's supported, I'm just correcting what you said because you said it is "a widely accepted standard"

You would be right, had you read the sentence properly. The emphasis is not on the singular word, but rather the objective idea.

A more common form of this example would be explained in plain ol' English; example: It's a widely accepted practice.

I'll leave the research of the definition of the words: "Practice" and "standard" up to you, Mouse❤️.
Is there any such thing as a woman of honor, and sincerity?

https://www.PutItOnMute.com/

4K HDR, WDR time-lapsed truck driving videos!
(Mar 6, 2018 08:32 PM)Mouse❤️ Wrote:  I'm aware. It's supported, I'm just correcting what you said because you said it is "a widely accepted standard"

I see, I guess I should've used slightly less ambiguous wording. Apologies.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by Tr0jandogSep 11, 2019 11:44 AM 0 135 Sep 11, 2019 11:44 AM
Last Post: Tr0jandog
[C#] by FiltrationJan 8, 2018 08:39 PM 6 673 Jan 8, 2018 08:39 PM
Last Post: gigajew
[Java] by KjetilApr 3, 2017 11:39 AM 4 259 Apr 3, 2017 11:39 AM
Last Post: Rin™