Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need some clarification on #pragma once

I've searched all over for some clarification on what #pragma once actually does and can't find definitive answers for some questions I still have.

Does #pragma once insure that the header file it is included in is only called once AS WELL AS that the headers which are included in said header file are not yet included? Also, if it is only called once, does that mean a .cpp file that needs a particular header will not be able to access it? If a header file is marked with #pragma once and included in a .cpp, can that header file be used again elsewhere?

These are the sorts of clarifications I am not finding. Sorry if there is documentation that clarifies this somewhere, but I really couldn't find any thing specific enough.

like image 676
NanoTree Avatar asked Feb 18 '14 03:02

NanoTree


People also ask

How do you use clarification?

I called to get clarification on what she had done and to get some tips on surviving the audit. He had already seen the report on the X-ray done at Drymen, and had requested clarification of one point. I sought clarification on a point he had made at the press conference.

What does clarification needed mean?

verb. To clarify something means to make it easier to understand, usually by explaining it in more detail.


1 Answers

#pragma once only guards a single file in a single translation unit, not counting its sub-hierarchy of inclusion. (However, if the file's second inclusion is prevented, it doesn't have an opportunity to doubly-include anything else.)

You can still include it again from another .cpp.

The file is usually identified by its inode number.

Note that #pragma once is strictly nonstandard, and most still prefer traditional #ifndef header guards.

like image 59
Potatoswatter Avatar answered Oct 20 '22 12:10

Potatoswatter