Skip to content

Prototype Generation With Typedef'd Types #298

@zachdeibert

Description

@zachdeibert

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedAssistance from the community is especially welcometopic: codeRelated to content of the project itselftopic: preprocessorRelated to sketch preprocessingtype: enhancementProposed improvement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy