Weird #define issue during compilation in Teensyduino with Teensy 4.0

Status
Not open for further replies.

amundsen

Well-known member
Hello,

I am using the Arduino IDE 1.8.13 and Teensyduino 1.5.3. On a Teensy 4.0, I want to use two serial ports as well as the USB port simultaneously.

This code was compiled without any issue a few months ago, before an upgrade to latest Arduino IDE and Teensyduino, as well as some other modifications in the code:
Code:
#define SenselSerialA Serial3
#define SenselSerialB Serial2

#define SenselDebugSerial Serial

Now #define SenselDebugSerial Serial triggers this error message when compiling:
sensel: In function 'void senselPrintFrameB(SenselFrameB*)':
sensel.h:33: error: expected ')' before 'Serial'
#define SenselDebugSerial Serial

I haven't post the whole code as it's spread in five tabs in the IDE but let me know if I want to after all.

Thank you in advance.
 
With the #define in place:

This :: sensel: In function 'void senselPrintFrameB(SenselFrameB*)':

will sensel: In function 'void senselPrintFrameB(Serial2*)':

Why is there a '*' after Serial2 from "SenselFrameB*"?
 
With the #define in place:

This :: sensel: In function 'void senselPrintFrameB(SenselFrameB*)':

will sensel: In function 'void senselPrintFrameB(Serial2*)':

Why is there a '*' after Serial2 from "SenselFrameB*"?

I guess it's the way the IDE/compiler reports the errors. The actual code is:
Code:
void senselPrintFrameB(SenselFrameB *frameB)
 
I'd not use #defines at all. You can always do

Code:
constexpr Stream& SenselSerialA  = Serial3;
constexpr Stream& SenselSerialB  = Serial2;
constexpr Stream& SenselDebugSerial = Serial;

to get correctly typed aliases for the Serials in c++.
 
All right, if I change the code like this...
Code:
constexpr Stream& SenselSerialA Serial3;
constexpr Stream& SenselSerialB Serial2;
constexpr Stream& SenselDebugSerial Serial;
...now I have another error message:
sensel.h:29: error: expected initializer before 'Serial3'
constexpr Stream& SenselSerialA Serial3;

^

sensel.h:30: error: expected initializer before 'Serial2'
constexpr Stream& SenselSerialB Serial2;
^

sensel.h:33: error: expected initializer before 'Serial'
constexpr Stream& SenselDebugSerial Serial;

^
 
I am totally lost now. First, I don't understand why the #define triggers an error message whereas it did not in previous versions of the program with the very same code. Now, with the change suggested by @luni, I have some other error messages, so could it be that the error message would be triggered by a bug in a distant part of the code?
 
I am totally lost now. First, I don't understand why the #define triggers an error message whereas it did not in previous versions of the program with the very same code. Now, with the change suggested by @luni, I have some other error messages, so could it be that the error message would be triggered by a bug in a distant part of the code?

If you want answers rather than speculation, you know what to do... Its staring you in the face on every forum page,

"Always post _complete source code_ & details to reproduce any issue!"
 
I am totally lost now.

I'm also lost too. Or blind at least. I can't see much here. I don't know which library you're really using. I can't see the complete code you're actually compiling. And I'm not even sure if I'm really seeing all the error messages when you say "I have some other error messages".

Can you understand how you're making this very difficult for us to effectively help you. Still, we're trying. But consider the suggestions you've received so far. They're based on little code fragments you've shown. But you didn't give us a link to the actual library code. You didn't give us a complete program we could copy into Arduino and click "Verify" to reproduce the problem. In msg #8, you didn't even bother to tell us what the new errors were.

Please, let us help you. Follow the "forum rule" which is shown in red at the top of every page on this forum. If you look at many prior threads, you'll see we're really good at solving this sort of problem. Sometimes we even figure these things out with blind guessing. But now with 8 fruitless messages, it's time to really show us what you're doing. Please don't keep making this a guessing game. We really can help you, if you'll just show the complete program and link to the actual library, so anyone reading can reproduce the actual error by loading your code into Arduino and clicking Verify.
 
All right, next time I'll post all the code and links directly. Sorry for the noise. Please consider my previous posts as a naive belief from an occasional programmer that fragments of code were enough to solve the issue.

However, I have decided to go back to older, fully functioning code and test a compilation after each change. Thank you for your help.
 
Status
Not open for further replies.
Back
Top