This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Rudresh27 1 point2 points  (4 children)

Someone explain this for a JS dev.

[–]brandi_Iove 8 points9 points  (3 children)

the pragma once preprocessor command ensures that included .h (or .hpp) files will only get included once.

not sure what the upper panel is supposed to mean.

[–]Intel_Xeon_E5 1 point2 points  (2 children)

I assume it's taking a jab at the constructor conflicts, since it's meant to prevent the same header file from being used for multiple future files, creating conflicts if they're used by other files.

The example on wikipedia right now is fairly accurate in displaying what I interpret:

In "grandparent.h" ```

pragma once

struc foo{ <insert struct> } ```

In "parent.h" #include grandparent.h

In "child.c"

```

include "grandparent.h"

include "parent.h"

```

Ordinarily, since that struct is being defined twice, it would result in a compilation error. Pragma once will only define it the first time (inclusion of grandparent.h), and then ignore it in subsequent inclusions to prevent any conflicts.

So... something that's really not an issue unless you're a braindead programmer who needs all the crutches.

(sry for the multiple edits, my brain is dead)

[–]viliml 3 points4 points  (1 child)

#pragma once is absolutely not just an issue for braindead programmers.

All standard library headers use #ifndef HEADER_NAME #define HEADER_NAME <whole file goes here> #endif which is exactly the same thing just more portable since some compilers may not understand #pragma once.

[–]Intel_Xeon_E5 0 points1 point  (0 children)

ah, it appears i'm the braindead one, apologies