Compiler support "Labels as Values"

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Compiler support "Labels as Values"

2,234件の閲覧回数
lpcware
NXP Employee
NXP Employee

Content originally posted in LPCWare by caprock on Thu Feb 21 11:03:58 MST 2013
How to make Compiler support "Labels as Values" as described in GNU Extensions

Red Suite (NXP Edition):
Version: Red Suite (NXP Edition) v4.2.2 [Build 361] [03/04/2012]

Win 7/ LPC1768

I am trying to compile a protothread example (Google Code Archive - Long-term storage for Google Code Project Hosting. )
and am getting compiler warnings for functions where the __GNUC__ extensions are
used to provide the [B][I]Labels as Values[/I][/B]. The resultant code seems to drop these warning lines from the binary axf file.

To see these warnings, I enabled the project Settings/Warnings and ticked Pedantic (-pedantic) and see the warning described as [B][I]ISO C forbids 'goto *expr;'[/I][/B].

I then added the [B]__GNUC__[/B] directive to Settings/Symbols with no change in behavior. In both cases, I see:
GNU C (Red Suite 2010Q4 by Code Red) version 4.5.1 (arm-none-eabi)
compiled by GNU C version 4.3.2, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1

I am fairly certain that there is a setting that I have overlooked, but can't
seem to locate it.
:confused:
Can anyone give me a hint as to why the GCC Extensions do not seem to override the
ISO C functionality?

0 件の賞賛
返信
12 返答(返信)

2,129件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by caprock on Thu Feb 28 15:12:35 MST 2013
Good thought! Probably a bad example provided by me.

While this clears the macro syntax complaints for the &(&label) declarations it now creates an error for any using macros referencing as Labelxx Undefined where .

These macros are part of the support for a context-based protothreads implementation such as:

/* Let other ready protothreads run, then resume this thread */
#define pt_yield(env) \
    do { \
        (env)->pt_func.label = &&PT_LABEL ; \
          ... 
        return PT_WAIT ; \
      PT_LABEL: ; \
    } while (0)


/* This should be at the beginning of every protothread function */
#define pt_resume(c) do { if ((c)->pt_func.label) goto *(c)->pt_func.label ; } while (0)


According to the GNU document


Quote:
6.3 Labels as Values

You can get the address of a label defined in the current function (or a containing function) with the unary operator `&&'. The value has type void *. This value is a constant and can be used wherever a constant of that type is valid. For example:

     void *ptr;
     /* ... */
     ptr = &&foo;
To use these values, you need to be able to jump to one. This is done with the computed goto statement1, goto *exp;. For example,

     goto *ptr;



I would think that the distinction between this macro form and the unary operator && (logical AND) may be the lack of white space following the &&.
0 件の賞賛
返信

2,129件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wrighflyer on Thu Feb 28 10:16:56 MST 2013
Surely:
int ptr = &(&foo);

would work if the intention is really to set the "ptr" to the address of the address of foo? Without the parentheses any C parser is going to see && as logical AND.
0 件の賞賛
返信

2,129件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Thu Feb 28 00:53:49 MST 2013
I would guess that the Indexer does not understand that syntax. The Indexer analyzes all your source code to allow syntax colouring, navigation, code-completion etc. Showing a syntax error is harmless, but annoying. You can changed Indexer config on the Indexer tab in preferences, but you can't 'teach' it about unknown syntax - unless you can write parsers in Java...
0 件の賞賛
返信

2,129件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by caprock on Wed Feb 27 16:15:21 MST 2013
The source file(s) may contain a bogus source tag as [B]? Syntax error[/B] where a goto statement is used or referenced.

These lines are [B]NOT[/B] marked as Warnings or Errors in the build, nor are they an issue with the compiler as the object is correctly produced. They seem to have something to do with the [B]C/C++/Editor/Content Assist[/B] within the IDE but I can not find a way to clear these syntax tags.

Testing suggests it may be caused by any reference to the [B]&&label[/B] declaration.

Does anyone know of an IDE setting that would fix or ignore this construct?

void fooP(void) {
int foo;
int ptr = &&foo;/* syntax error ? tag */
}
0 件の賞賛
返信

2,129件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by caprock on Sat Feb 23 12:46:44 MST 2013
Thank you for testing and the suggestions.

I have put together a much smaller test program and have confirmed that with the following settings:

- Settings/Miscellaneous/C Dialect: Compiler default
- Settings/Warnings/All warnings (-Wall)

The compilers LPCXpresso V5.1.2 and Red Suite (NXP Edition) v4.2.2 create the code properly and without noting any build errors or warnings.

However, with this small test, I still have 4 source code ? tags with Syntax error. Changing the Warnings to no items ticked has no effect. This is true with both compilers.

While this does not cause a compiler failure to create object code, it is confusing to develop when there are more than 40 lines showing Syntax errors while using the original source files. (http://code.google.com/p/protothread/)

Perhaps it is just my system, but I just don't know. Perhaps I can alter the use of Label as Values to eliminate these lines. TBD

I can provide the project file if desired.
Thank you for the support
0 件の賞賛
返信

2,129件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Sat Feb 23 05:18:11 MST 2013
"Labels as values" compile fine here, using the compiler default language setting.

As you have obviously added "-pedantic" to your compiler options in order to get the "ISO C forbids" message, if you are seeing this message as an error rather than a warning, I assume that you have also added "-Werror" to turn this into an error.

If you want more help, suggest that you post the content of the build console...

http://support.code-red-tech.com/CodeRedWiki/BuildConsole

Regards,
CodeRedSupport
0 件の賞賛
返信

2,129件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by caprock on Fri Feb 22 13:51:19 MST 2013
Many thanks to TheFallGuy for the assistance. I had never thought of the Misc settings for the language dialect.

I upgraded my LPCXpresso license to the 5.1.2 to give this a try. Using the compiler dialect gnu90 & gnu99 selections results in the same error: ISO C 'goto *expr;'[-pedantic].

Further examination of the GCC 4.6.2 extensions has the feature 'Labels as Values' listed, but since this does not compile correctly, it is unsure whether this compiler supports this language extension. Perhaps only the compiler folks can provide a definitive answer. 

Question for Code Red Team: is the GCC extension Labels as Values supported with GCC 4.6.2?
0 件の賞賛
返信

2,129件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Fri Feb 22 02:05:21 MST 2013
Open the Settings, go the compiler Miscellaneous tab and choose the C Dialect from the drop-down list.

I see you are using an out-of date version of the product. Last of the v4 releases was v4.3.0. Latest version is now 5.1.2
0 件の賞賛
返信

2,129件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by caprock on Thu Feb 21 14:49:49 MST 2013
The only Language Dialect that I can find is in the help section 3.4, and I tried -std=gnu99 in the Settings/Symbols and get an error <command-line>:0:1: error: macro names must be identifiers

A search of the help did not lead me into where or how to change the dialect.

Anyone? Thanks all.
0 件の賞賛
返信

2,129件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by caprock on Thu Feb 21 12:37:37 MST 2013
Thanks - can you give me more direction for this? Not sure of what/where to change.
0 件の賞賛
返信

2,129件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Thu Feb 21 11:43:25 MST 2013
Change the language dialect in the compiler settings.
0 件の賞賛
返信

2,129件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by caprock on Thu Feb 21 11:06:19 MST 2013
post dropped link: protothread example (http://code.google.com/p/protothread/)
0 件の賞賛
返信