Jump to content
  • 0

Global variables in SDK


Antonio Fasano

Question

Hi, Guys,

I have been seeing a strange behaviour in my C applications in SDK.

Suppose I define a global variable like  int X; outside the main() subroutine in main.c 

If I try to use that global variable in another file, say, echo.c, I get an error message that the  variable in undeclared and is being used for the first time in this function  (Inside echo.c).

What am I doing wrong ?

Thanks

Antonio Fasano

Brazil

 

 

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

Hello @Antonio Fasano

A global variable is a variable that is declared outside all functions and it can be used in all functions, but into the same c/cpp file. If you want to pass variables between two different files, you need functions. For example you declare the prototype of the function into the main.c file and the body into the echo.c file. In this way you can pass your "int x" variable trough one of the function parameters. I hope I was clearly enough.

 

Best Regards,

Bogdan Vanca

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...