Jump to content
Sign in to follow this  
drumanart

Header File Quiestion

Recommended Posts

Hello.

 

In my heades file I decleare a variable:

 

//Header test.h:

 

#define TEST

 

#ifndef TEST

volatile bit spi_cs @ PORTC . 2;

bit spi_cs_tris @ TRISC . 2;

#endif // TEST

 

//

//

 

Than on the main program I try to use the variable:

 

main test.c

 

spi_cs_tris = 0; // Portc,2 as output.

spi_cs = 1; // Portc, 2 Hi.

 

For some reason the variable "spi_cs" gives an error (variable not found) in compiling the main code.

What is wrong?

 

Thanks Martin

Share this post


Link to post
Share on other sites

Hello.

 

In my heades file I decleare a variable:

 

//Header test.h:

 

#define TEST

 

#ifndef TEST

volatile bit spi_cs @ PORTC . 2;

bit spi_cs_tris @ TRISC . 2;

#endif // TEST

 

//

//

 

Than on the main program I try to use the variable:

 

main test.c

 

spi_cs_tris = 0; // Portc,2 as output.

spi_cs = 1; // Portc, 2 Hi.

 

For some reason the variable "spi_cs" gives an error (variable not found) in compiling the main code.

What is wrong?

 

Thanks Martin

 

Martin,

 

You have defined TEST and then carried out a check to see if is NOT defined. Since this must be false then the variables will not be defined.

Change the #ifndef TEST to #ifdef TEST and all should be fine.

 

Regards

 

davidb

Share this post


Link to post
Share on other sites

Defining variables in header files is dangerous/dirty as if more than one file includes that header file an error will result. Also, it makes it hard to figure out what the variable type is when you can't search for it in the file you are playing with.

 

Please ignore me if you know better.

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...