0

I have these files that were given to me to solve and I have some doubts about header guard.

  1. In testGuards.h, there is a define like __HEADER_GUILD_SAFEBOX__, but the #ifdef asks if __GUILD_SAFEBOX__ is defined, so I don't know if this #ifdef should ask about __HEADER_GUILD_SAFEBOX__ instead of __GUILD_SAFEBOX__.

  2. In testCpp.h I ask if __GUILD_SAFEBOX__ is already defined, but, as far I know, it is already defined in testGuards.h, but here (in cpp), we never enter into the #ifdef, and I not know, how to know if is not defined, and if not defined, then define it.

I have 2 codes.

testGuards.h

#ifndef __HEADER_GUILD_SAFEBOX__
#define __HEADER_GUILD_SAFEBOX__

#include "stdafx.h"

#ifdef __GUILD_SAFEBOX__
[...]
#endif

testCpp.cpp

#include "stdafx.h"

#ifdef __GUILD_SAFEBOX__
#include "../common/tables.h"
[...]
#endif
tripleee
  • 175,061
  • 34
  • 275
  • 318
Alejoo
  • 13
  • 5
  • 2
    Identifiers (including macro names) containing a double underscore are [reserved for the implementation](http://stackoverflow.com/a/228797/501250) (compiler and standard library). **You should not use them.** – cdhowie Apr 11 '17 at 04:23
  • I think you are not meant to put stdafx.h anywhere other than the first line of the file – M.M Apr 11 '17 at 07:41
  • @cdhowie Thanks so much, is very useful to me, I readed all. I changed __HEADER_GUILD_SAFEBOX__ for __GUILD_SAFEBOX_H and works fine. – Alejoo Apr 12 '17 at 05:55

1 Answers1

0

You could print a message, as a header is included. After that you can manually/automatically check whatever you want.

Follow this answer:

The warning directive is probably the closest you'll get, but it's not entirely platform-independent:

#warning "C Preprocessor got here!"

AFAIK this works on most compilers except MSVC, on which you'll have to use a pragma directive:

#pragma message ( "C Preprocessor got here!" )
Community
  • 1
  • 1
c4pQ
  • 884
  • 8
  • 28