cancel
Showing results for 
Search instead for 
Did you mean: 

Why can't I declare char? [SOLVED]

SHelg.1
Associate II

I am using STM32 Cube IDE with NUCLEO-L4P5ZG

below is my code

void function (int dir, int runtime){

int Run=1;

int bytes_per_reading_gyro = 72;

int bytes_per_reading_echo = 29;

char gyro_reading[bytes_per_reading_gyro];;

int echo_reading[bytes_per_reading_echo];

[more code below]

}

I want both gyro_reading and echo_reading to be char[], but I get the error 'gyro_reading' undeclared (first use in this function) when I try to declare it as char.

int foo[foo_len]; is fine

char foo[foo_len]; gives 'foo' undeclared (first use in this function)

char foo = 'f'; gives 'foo' undeclared (first use in this function)

char foo[foo_len] = {'\0'}; gives expected expression before '{' token

Is there a way I can declare and use char arrays?

[SOLVED edit] I had used #define char somewhere else in the code

4 REPLIES 4

Two semi-colons?

Any defines/macros replacing code unexpectedly? Perhaps look at pre-processor output?

Variable size auto allocations? If these are constants perhaps use #define values.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
SHelg.1
Associate II

Only instance of two semi-colons I can find in the entire file is within for(;;)

Both bytes_per_reading_gyro and bytes_per_reading_echo are constants, so I moved them to main.h and have them as #define values now.

I still can't declare char

I'll look if tthere are defines or macros that interfere.

Thank you

Edit: Also went through the entire file searching with the regex ^([^;]+);([^;]+); to see if there was something missed by searching for ;; found no instances of a semi-colon too many

TDK
Guru

> Only instance of two semi-colons I can find in the entire file is within for(;;)

What about this one?

> char gyro_reading[bytes_per_reading_gyro];;

Doesn't explain the error though. Perhaps mismatched brackets or other syntax error. There's no error in the array declaration.

Was char #defined somewhere?

If you feel a post has answered your question, please click "Accept as Solution".
SHelg.1
Associate II

Char was defined somewhere. Removing it solved my issue.

Thank you all!