Hack Forums
[C] Include Guards Names - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C] Include Guards Names (/showthread.php?tid=5807868)



Include Guards Names - Gl4diat0r - Mar 5, 2018

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?


RE: Include Guards Names - P4r4517 - Mar 5, 2018

Nothing will happen, in fact those definitions do not have any real connection with the filename. Its just common sense.


RE: Include Guards Names - Annabelle Lee - Mar 5, 2018

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


RE: Include Guards Names - Mouse❤️ - Mar 5, 2018

The wikipedia link says #pragma once is not standard.


RE: Include Guards Names - Irritiable - Mar 6, 2018

(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/23696115/is-pragma-once-part-of-the-c11-standard

It is inarguably non-standard, but is widely accepted by nearly every modern compiler in 2018.


RE: Include Guards Names - Annabelle Lee - Mar 6, 2018

(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."


RE: Include Guards Names - Mouse❤️ - Mar 6, 2018

I'm aware. It's supported, I'm just correcting what you said because you said it is "a widely accepted standard"


RE: Include Guards Names - Irritiable - Mar 7, 2018

(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❤️.


RE: Include Guards Names - Annabelle Lee - Mar 7, 2018

(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.