Must #ifndef be the same as the file name?

I've been trying to compile a helper class into a program. After way more time than I want to admit, I discovered that my files compile if I use the file name with an underscore where the period should be. It doesn't compile if I just drop the .h? Is that a requirement? The code looks like:

#ifndef ds18b20Handler
#define ds18b20Handler
#ifndef ds18b20Handler_H
#define ds18b20Handler_H

The first code display all sorts of errors. The second compiles just fine. What is up with that?

you can define near to any name, not file name, just letters and numbers, some symbols.

#define setArduPin2High (digitalWrite(2,HIGH))
#define  isPinHigh(x) digitalRead(x)

My guess is that this name is equal to your class name.
Maybe you can copy your errors in your next post?

Yes, it is the same as my class name. But, now I'm really confused. I changed my code back and it still compiles. There must have been another error somewhere masquerading as the #ifndef issue.

Thank you for the help.

the header guard needs to be unique and unlikely to be non-unique if named after the file

2 Likes

if you need an include guard, consider to use pragma once .

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.