Is using HPP acceptable or common practice?

up untill now i've never heard of hpp header files, but from my POV , if you're using header files that contain pure virtual classes the header file should hpp, is this common practive in arduino as well? c++ - *.h or *.hpp for your class definitions - Stack Overflow

there's nothing that prevents the use of file extensions.

Typically not, based on the code I've looked at. I've seen .hpp sometimes used to contain template implementations.

Do you intend to write a lot of C code and intermingle it with C++ code? If so, that might be a reason to do it (as noted in the first answer at the link you posted). If you intend to stick with C++, then it probably doesn't matter.

See my Post #5 Here for a basic guide to breaking up larger projects into separate files. I only mention .h files there. But you could substitute .hpp if it makes you happy.

thanks, i actually don't want to write c code at all, but i currently need to use c library from cpp..
and one of the biggest problems i've encountered is that c library uses _Bool
and i keep getting various compile errors using it (i'm also trying to compile those classes in regular g++)

As that's not a standard C type or value, it's likely #defined in a header file somewhere.

If you are thinking of using them in sketch root files (as opposed to libraries, cores, or in the src subfolder of the sketch), you should note that support for this file extension in sketches is somewhat recent:

https://arduino.github.io/arduino-cli/latest/sketch-specification/#additional-code-files

Sketches may consist of multiple code files.

The following extensions are supported:

...

  • .h, .hpp, .hh 1 - Header files.

...

1 .hpp and .hh supported from Arduino IDE 1.8.0/arduino-builder 1.3.22.

So if you think you might share the sketch with people who are using an older version of Arduino IDE for some reason (may sound unlikely, but it does happen), then it would be better to avoid the use of the extensions with recently added support.

well it's sortof defined in <stdbool.h> and according to this, it's actually a keyword added in C99 ..but i'm using g++

Ahhh ....
I assume you have the source code for the library you're trying to use. Can you convert it to C++ and have all your code compiled in the same language by the same compiler?

actually i'm trying to avoid changing anything in the library at all costs as it's not mine, so any event of future changes to it, will be easier to merge.
the end result is to be able to execute it untouched either from arduino project (which is happening right now in vscode ) or from a regular main.cpp file, for the classes that accessing hardware parts (LCD, RTC etc..) are defined as pure virtual classes, that can have 2 implementations, a real one and as a mock, trying to do that with gcc fails, so G++ is used instead thus failing with _Bool
i don't think there's any way to do that in one liner with vscode, but using makefiles gives me a migrane

I can't comment on your IDE, workflow, or toolchain problems. But, plain old vanilla Arduino IDE seems to know what a _Bool is and it's perfectly happy calling functions compiled as C code:

Main .ino File:

extern "C" {
  _Bool cFunction(_Bool in);
}

void setup() {
  Serial.begin(115200);
  delay(1000);

  if (cFunction(true)) {
    Serial.println("True");
  } else {
    Serial.println("False");
  }

  if (cFunction(false)) {
    Serial.println("True");
  } else {
    Serial.println("False");
  }
}

void loop() {
}

Cfunct.c:

_Bool cFunction(_Bool in) {
  return in;
}

Serial Monitor:

True
False

oh vscode with platform.io has now problem compiling it either, it's has full automatic depdendency scan and everything
the problem starts when i want to run and debug things not as sketch file but as plain old c and cpp files, i thought i would seperate the actual implemenations into subclasses i could build source code which standard c and cpp on my own machines with debug features.
this would have worked if it weren't for the _Bool thing, but you run g++ and use stdbool headers it operates on cpp mode rather than c mode, so this would mean compiling just the c code first with gcc and compile the rest with g++

I know absolutely nothing about either of those tools. Perhaps others here do and can help.

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