• 0
Antonio Fasano

Global variables in SDK

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

 

 

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now