What is the difference between the following two blocks of code?
  (1)
  int a_sub(. . .)
  {
  static int an_int=3;
  . . .
  }
  (2)
  int an_int=3;
  int a_sub(. . .)
  {
  . . .
  }
   
  Is “static” redundant in the following block of code?
  (3)
  static int an_int=3;
  int a_sub(. . .)
  {
  . . .
  }
  

Robert Spanton <[email protected]> wrote:
  Hi,

I'm having some trouble with using static and non-static global variables.

I've cut down the source to the smallest amount that I can whilst
still having the error. I have two C files:

*** time.c ***

unsigned long int the_time = 0;

unsigned long int time_get( void )
{
return the_time;
}

*** main.c ***

static unsigned char count = 0;

int main( void )
{
}

***

If I compile them with the command:

% msp430-gcc -o main main.c time.c -mmcu=msp430x169

I get the following output:
/tmp/ccAOuihe.o(.text+0x6): In function `time_get':
: internal error: unsupported relocation error
/tmp/ccAOuihe.o(.text+0xa): In function `time_get':
: internal error: unsupported relocation error

I have noted two more things that may be relevant:

1) If I compile the two files as separate object files then link them,
then there is no error. However, I think this is undesirable because it
will affect the optimisation that I get.

2) If I remove "static" from main.c, then it works with no errors. I've
actually moved that variable from an interrupt handler which had it as a
static variable.

Can anyone shed any light on what's happening? I'm using the "cdk4msp"
rpms, which report to be verion 3.3.2. Would this problem be solved if I
used a later version of the compiler?

Cheers,

Rob Spanton


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Mspgcc-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users



Lichen Wang

Darwin was wrong. Monkeys might have evolved. Human did not.


 
---------------------------------
Sponsored Link

Mortgage rates near 39yr lows. $510,000 Mortgage for $1,698/mo -   Calculate 
new house payment

Reply via email to