Compile Error using struct pointer in function

Status
Not open for further replies.

Andreas

Member
Dear All,
I am running into a stupid compile error for Teensy 3.1 with the test code shown below.
The very same code compiles under Arduino 1.05 for Arduino UNO without error.
The usage of a pointer to a struct should be allowed in C or C++.

Code:
/*
   Sample code to reproduce error for Teensy 3.1
 */
//-----------------------------------------------
struct mytask_t {
	uint16_t period;
	uint16_t cpu;
} MyTask = {10, 20};
//-----------------------------------------------
void myprintTask(mytask_t* task) {
	Serial.println(task->period);
}
//-----------------------------------------------
void setup() { 
	Serial.println("Start ...");
	myprintTask(&MyTask);
}
//-----------------------------------------------
void loop() {}

Under Atmel Studio 6 with VisualMicro the following output show up:
Code:
Compiling 'Blink' for 'Teensy 3.1'
Build folder: file:///C:/Users/Andreas/AppData/Local/VMicro/Arduino/Builds/Blink/teensy31
Summary: Header=1 Prototypes=4 Imports=0
Additional Defines: F_CPU=96000000;USB_SERIAL;LAYOUT_US_ENGLISH;VISUALMICRO_COMPILER_VER=1;
Architecture Tools: c:\Arduino-105\hardware\tools\arm-none-eabi\bin\
GCC: 4.7.2
Sketchbook: file:///c:/Arduino-105
Core Include Paths
Include Path 'c:\Arduino-105\hardware\teensy\cores\teensy3'
c:\Arduino-105\hardware\tools\arm-none-eabi\bin\arm-none-eabi-g++ -c -g -Os -fno-exceptions -ffunction-sections -fdata-sections -Wall -mcpu=cortex-m4 -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -felide-constructors -std=gnu++0x -I"c:\Arduino-105\hardware\teensy\cores\teensy3" -o "C:\Users\Andreas\AppData\Local\VMicro\Arduino\Builds\Blink\teensy31\Blink.cpp.o"  "C:\Users\Andreas\AppData\Local\VMicro\Arduino\Builds\Blink\teensy31\Blink.cpp"  -DF_CPU=96000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH -DVISUALMICRO_COMPILER_VER=1  -mthumb -nostdlib -D__MK20DX256__ -DTEENSYDUINO=118  -fno-rtti
Blink.ino:2:18: error: variable or field 'myprintTask' declared void
Blink.ino:2:18: error: 'mytask_t' was not declared in this scope
Blink.ino:2:28: error: 'task' was not declared in this scope
Error compiling

Any suggestions would be appreciated.
Andreas

===< U P D A T E >======================
Problem solved by adding "struct" to signature

void myprintTask(struct mytask_t* task) {
Serial.println(task->period);
}

Solution described in:
http://stackoverflow.com/questions/1793971/why-does-gcc-give-me-a-syntax-error-when-trying-to-return-a-struct-pointer
 
Last edited:
Right. That's how I do it for structs as I don't care for typedef'ing a struct, for simple program as it's just a distraction.
 
Status
Not open for further replies.
Back
Top