Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove #pragma once warnings

I am using #pragma once in my .cpps and .hpps and because of that I get a warning for each file that uses it. I have not found any option to disable this kind of warning, only the thing of #ifndef MY_FILE_H #define MY_FILE_H /*...*/ #endif.

So would you recommend me to replace each #pragma once with ifndefs?

in header:

#define MYFILE_H
// all the header

and in the other files:

#ifndef MYFILE_H
#include "myfile.hpp"
#endif
// the rest of the file

What do you think, is it better to use it like this? Or there is an option to disable the #pragma once warnings in GCC, that I do not know?

like image 555
thedarkside ofthemoon Avatar asked Apr 17 '14 14:04

thedarkside ofthemoon


People also ask

What is the same meaning of remove?

abolish, clear away, cut out, delete, discard, discharge, dismiss, eliminate, erase, evacuate, expel, extract, get rid of, oust, pull out, raise, separate, ship, take out, transfer.

Is remove an intransitive verb?

Verb. (transitive) To delete.


1 Answers

The common approach is to place the guard in the .h file only:

#ifndef MYFILE_H
#define MYFILE_H
// all your myfile.hpp here
#endif

or

#pragma once
// all your myfile.hpp here

The rest of files (other .cpp) should do nothing regarding the guards. You should not get warnings by doing this.

like image 92
ChronoTrigger Avatar answered Oct 19 '22 01:10

ChronoTrigger