Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prototype Generation With Typedef'd Types #298

Open
zachdeibert opened this issue Oct 3, 2018 · 0 comments
Open

Prototype Generation With Typedef'd Types #298

zachdeibert opened this issue Oct 3, 2018 · 0 comments
Labels
help wanted Assistance from the community is especially welcome topic: code Related to content of the project itself topic: preprocessor Related to sketch preprocessing type: enhancement Proposed improvement

Comments

@zachdeibert
Copy link

zachdeibert commented Oct 3, 2018

When the Arduino IDE attempts to generate the prototypes for a function where the types that are a part of that prototype are defined in a header file, the IDE does not always include the header file defining the type before the generated prototype is emitted to the file that is passed into G++.

(Code is available for download here)

arduino-ide-prototype-bug/arduino-ide-prototype-bug.ino

void setup() {
  Serial.begin(115200);
}

void loop() {
  Serial.print("2 + 2 = ");
  Serial.println(add(2, 2));
  delay(1000);
}

arduino-ide-prototype-bug/add.ino

#include "number.h"

number_t add(number_t a, number_t b) {
  return a + b;
}

arduino-ide-prototype-bug/number.h

typedef int number_t;

Build Output:

/home/zach/software/arduino-1.8.5/arduino-builder -dump-prefs -logger=machine -hardware /home/zach/software/arduino-1.8.5/hardware -tools /home/zach/software/arduino-1.8.5/tools-builder -tools /home/zach/software/arduino-1.8.5/hardware/tools/avr -built-in-libraries /home/zach/software/arduino-1.8.5/libraries -libraries /home/zach/Arduino/libraries -fqbn=arduino:avr:nano:cpu=atmega328 -ide-version=10805 -build-path /tmp/arduino_build_613863 -warnings=all -build-cache /tmp/arduino_cache_167137 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=/home/zach/software/arduino-1.8.5/hardware/tools/avr -prefs=runtime.tools.arduinoOTA.path=/home/zach/software/arduino-1.8.5/hardware/tools/avr -prefs=runtime.tools.avr-gcc.path=/home/zach/software/arduino-1.8.5/hardware/tools/avr -verbose /code/github.com/zachdeibert/arduino-ide-prototype-bug/arduino-ide-prototype-bug.ino
/home/zach/software/arduino-1.8.5/arduino-builder -compile -logger=machine -hardware /home/zach/software/arduino-1.8.5/hardware -tools /home/zach/software/arduino-1.8.5/tools-builder -tools /home/zach/software/arduino-1.8.5/hardware/tools/avr -built-in-libraries /home/zach/software/arduino-1.8.5/libraries -libraries /home/zach/Arduino/libraries -fqbn=arduino:avr:nano:cpu=atmega328 -ide-version=10805 -build-path /tmp/arduino_build_613863 -warnings=all -build-cache /tmp/arduino_cache_167137 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=/home/zach/software/arduino-1.8.5/hardware/tools/avr -prefs=runtime.tools.arduinoOTA.path=/home/zach/software/arduino-1.8.5/hardware/tools/avr -prefs=runtime.tools.avr-gcc.path=/home/zach/software/arduino-1.8.5/hardware/tools/avr -verbose /code/github.com/zachdeibert/arduino-ide-prototype-bug/arduino-ide-prototype-bug.ino
Using board 'nano' from platform in folder: /home/zach/software/arduino-1.8.5/hardware/arduino/avr
Using core 'arduino' from platform in folder: /home/zach/software/arduino-1.8.5/hardware/arduino/avr
Detecting libraries used...
"/home/zach/software/arduino-1.8.5/hardware/tools/avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-I/home/zach/software/arduino-1.8.5/hardware/arduino/avr/cores/arduino" "-I/home/zach/software/arduino-1.8.5/hardware/arduino/avr/variants/eightanaloginputs" "/tmp/arduino_build_613863/sketch/arduino-ide-prototype-bug.ino.cpp" -o "/dev/null"
Generating function prototypes...
"/home/zach/software/arduino-1.8.5/hardware/tools/avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-I/home/zach/software/arduino-1.8.5/hardware/arduino/avr/cores/arduino" "-I/home/zach/software/arduino-1.8.5/hardware/arduino/avr/variants/eightanaloginputs" "/tmp/arduino_build_613863/sketch/arduino-ide-prototype-bug.ino.cpp" -o "/tmp/arduino_build_613863/preproc/ctags_target_for_gcc_minus_e.cpp"
"/home/zach/software/arduino-1.8.5/tools-builder/ctags/5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "/tmp/arduino_build_613863/preproc/ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"/home/zach/software/arduino-1.8.5/hardware/tools/avr/bin/avr-g++" -c -g -Os -Wall -Wextra -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-I/home/zach/software/arduino-1.8.5/hardware/arduino/avr/cores/arduino" "-I/home/zach/software/arduino-1.8.5/hardware/arduino/avr/variants/eightanaloginputs" "/tmp/arduino_build_613863/sketch/arduino-ide-prototype-bug.ino.cpp" -o "/tmp/arduino_build_613863/sketch/arduino-ide-prototype-bug.ino.cpp.o"
add:3: error: 'number_t' does not name a type
 number_t add(number_t a, number_t b) {
 ^
/code/github.com/zachdeibert/arduino-ide-prototype-bug/arduino-ide-prototype-bug.ino: In function 'void loop()':
arduino-ide-prototype-bug:7: error: 'add' was not declared in this scope
   Serial.println(add(2, 2));
                          ^
exit status 1
'number_t' does not name a type

C++ file generation:

#include <Arduino.h>
#line 1 "/code/github.com/zachdeibert/arduino-ide-prototype-bug/arduino-ide-prototype-bug.ino"
#line 1 "/code/github.com/zachdeibert/arduino-ide-prototype-bug/arduino-ide-prototype-bug.ino"
#line 1 "/code/github.com/zachdeibert/arduino-ide-prototype-bug/arduino-ide-prototype-bug.ino"
void setup();
#line 5 "/code/github.com/zachdeibert/arduino-ide-prototype-bug/arduino-ide-prototype-bug.ino"
void loop();
#line 3 "/code/github.com/zachdeibert/arduino-ide-prototype-bug/add.ino"
number_t add(number_t a, number_t b);
#line 1 "/code/github.com/zachdeibert/arduino-ide-prototype-bug/arduino-ide-prototype-bug.ino"
void setup() {
  Serial.begin(115200);
}

void loop() {
  Serial.print("2 + 2 = ");
  Serial.println(add(2, 2));
  delay(1000);
}


#line 1 "/code/github.com/zachdeibert/arduino-ide-prototype-bug/add.ino"
#include "number.h"

number_t add(number_t a, number_t b) {
  return a + b;
}

Workaround: Including all header files into the main INO fixes the problem, but that should not be required.

(originally at arduino/Arduino#8050)

@facchinm facchinm added enhancement help wanted Assistance from the community is especially welcome labels Oct 4, 2018
@rsora rsora added the type: enhancement Proposed improvement label Sep 22, 2021
@per1234 per1234 added topic: preprocessor Related to sketch preprocessing topic: code Related to content of the project itself labels Oct 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Assistance from the community is especially welcome topic: code Related to content of the project itself topic: preprocessor Related to sketch preprocessing type: enhancement Proposed improvement
Projects
None yet
Development

No branches or pull requests

5 participants