strange problem with __FUNCTION__

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

strange problem with __FUNCTION__

Rolf Freitag

Hi,

when i use

#   ifndef __FUNCTION__
#      define __FUNCTION__ __func__
#   endif

before

  _BIC_SR_IRQ (LPM4_bits);  // line 42

mpsgcc reports

signal.c:42: syntax error before "__func__"

although i can find no reason why the define should be an error
and the ifndef block works without problems on PC and ARM9
in kernel and user space.
I reduced the problem to this minimal example file tmp.c:

#   include <io.h>
void
kernel_panic (void)
{
#   ifndef __FUNCTION__
#      define __FUNCTION__ __func__
#   endif
  _BIC_SR_IRQ (LPM4_bits);  
  return;
}

and i compiled with

msp430-gcc -mmcu=msp430x168 -O2 -Wall -g -c -o tmp.o tmp.c

Any ideas what's wrong?

Regards,

Rolf



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Reply | Threaded
Open this post in threaded view
|

Re: strange problem with __FUNCTION__

Chris Liechti
[hidden email] wrote:

> Hi,
>
> when i use
>
> #   ifndef __FUNCTION__
> #      define __FUNCTION__ __func__
> #   endif
>
> before
>
>   _BIC_SR_IRQ (LPM4_bits);  // line 42

this macro uses string concatenation feature of the preprocessor to
calculate the stack depth of the currrent frame (so that the generated
insn "bic #const, offset(SP)" clears the bits on the copy of SR on the
stack)

"__func__" is a "const char *", string concatenation does not work there...

gcc 3.2.3 defines __FUNCTION__. strange that the #ifndef does not "see" it.

chris


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Reply | Threaded
Open this post in threaded view
|

Re: strange problem with __FUNCTION__

Rolf Freitag
In reply to this post by Rolf Freitag

Hi,

> > when i use
> >
> > #   ifndef __FUNCTION__
> > #      define __FUNCTION__ __func__
> > #   endif
> >
> > before
> >
> >   _BIC_SR_IRQ (LPM4_bits);  // line 42
>
> this macro uses string concatenation feature of the preprocessor to
> calculate the stack depth of the currrent frame (so that the generated
> insn "bic #const, offset(SP)" clears the bits on the copy of SR on the
> stack)
>
> "__func__" is a "const char *", string concatenation does not work there...
>
> gcc 3.2.3 defines __FUNCTION__. strange that the #ifndef does not "see" it.

yes, i can use on the PC e. g.

#include <stdio.h>
int main() {
printf("%s\n", __FUNCTION__);
return 0; }

and it compiles and the executable prints the function.
But when i use

#ifndef __FUNCTION__
#  error
#endif

compilation always stops at #error and
#undef __FUNCTION__
does not work.
So for printf and other functions __FUNCTION__ is defined but it is
not defined for ifdef or defined() and it is impossible to undefine __FUNCTION__!

The error message from mspgcc also vanishes when i comment or delete the line
_BIC_SR_IRQ (LPM4_bits);

It seems the change from the half to the full definition of __FUNCTION__ confuses
the _BIC_SR_IRQ macro.

Regards,

Rolf



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users