VS2008 and __gc

classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|

VS2008 and __gc

Wesley Smith
Hi list,
I was porting some code to Windows and was surprised that a method:

static in __gc(lua_State *L)

was using the "__gc" keyword.  Apparently managed C++ on windows
defines __gc for itself and gives errors in my code when I use it to
define a function.   The errors said to use /clr:oldsyntax as a
compiler switch, which is even worse since that is apparently
deprecated and will not even compile.  Anyone know how to turn off
managed C++ to avoid this problem?

thanks,
wes

Reply | Threaded
Open this post in threaded view
|

RE: VS2008 and __gc

Erik Cassel-2
It sounds like you created a managed C++ project.  If that was not your
intention, create a Win32 C++ project (or ATL or whatever) instead.  A
managed C++ project will require .NET to be present on the target machine. 

If you want to use managed C++ classes for some of your work, then you can
selectively turn off managed C++ for specific c/cpp files. Look in the C/C++
property pages of the Lua c-file.

-Erik



> -----Original Message-----
> From: [hidden email] [[hidden email]
> [hidden email]] On Behalf Of Wesley Smith
> Sent: Friday, May 09, 2008 10:07 AM
> To: Lua list
> Subject: VS2008 and __gc
> 
> Hi list,
> I was porting some code to Windows and was surprised that a method:
> 
> static in __gc(lua_State *L)
> 
> was using the "__gc" keyword.  Apparently managed C++ on windows
> defines __gc for itself and gives errors in my code when I use it to
> define a function.   The errors said to use /clr:oldsyntax as a
> compiler switch, which is even worse since that is apparently
> deprecated and will not even compile.  Anyone know how to turn off
> managed C++ to avoid this problem?
> 
> thanks,
> wes


Reply | Threaded
Open this post in threaded view
|

Re: VS2008 and __gc

Wesley Smith
I definitely do not want to create a managed C++ project.  Is there a
setting to turn this off or do I have to completely rebuild the
project?

wes

On Fri, May 9, 2008 at 10:26 AM, Erik Cassel <[hidden email]> wrote:
>
> It sounds like you created a managed C++ project.  If that was not your
> intention, create a Win32 C++ project (or ATL or whatever) instead.  A
> managed C++ project will require .NET to be present on the target machine.
>
> If you want to use managed C++ classes for some of your work, then you can
> selectively turn off managed C++ for specific c/cpp files. Look in the C/C++
> property pages of the Lua c-file.
>
> -Erik
>
>
>
>> -----Original Message-----
>> From: [hidden email] [[hidden email]
>> [hidden email]] On Behalf Of Wesley Smith
>> Sent: Friday, May 09, 2008 10:07 AM
>> To: Lua list
>> Subject: VS2008 and __gc
>>
>> Hi list,
>> I was porting some code to Windows and was surprised that a method:
>>
>> static in __gc(lua_State *L)
>>
>> was using the "__gc" keyword.  Apparently managed C++ on windows
>> defines __gc for itself and gives errors in my code when I use it to
>> define a function.   The errors said to use /clr:oldsyntax as a
>> compiler switch, which is even worse since that is apparently
>> deprecated and will not even compile.  Anyone know how to turn off
>> managed C++ to avoid this problem?
>>
>> thanks,
>> wes
>
>

Reply | Threaded
Open this post in threaded view
|

Re: VS2008 and __gc

Chip Salzenberg
In reply to this post by Wesley Smith
On Fri, May 09, 2008 at 10:06:39AM -0700, Wesley Smith wrote:
> Hi list,
> I was porting some code to Windows and was surprised that a method:
>    static in __gc(lua_State *L)
> was using the "__gc" keyword.

If you write your code in compliance with standards, that shouldn't matter.
Any identifier starting with double underscores is in the purview of the
implementation, and your code must not define it in any way.
-- 
Chip Salzenberg <[hidden email]>

Reply | Threaded
Open this post in threaded view
|

Re: VS2008 and __gc

Stephen Kellett
In reply to this post by Wesley Smith


Wesley Smith wrote:
I definitely do not want to create a managed C++ project.  Is there a
setting to turn this off or do I have to completely rebuild the
project?

That would be a rebuild. Consult your compiler/linker documentation - Help menu in Visual Studio. I haven't got VS2008 on this machine, so I can't look it up right now.

Stephen

Reply | Threaded
Open this post in threaded view
|

Re: VS2008 and __gc

Wesley Smith
In reply to this post by Chip Salzenberg
On Fri, May 9, 2008 at 11:20 AM, Chip Salzenberg <[hidden email]> wrote:
> On Fri, May 09, 2008 at 10:06:39AM -0700, Wesley Smith wrote:
>> Hi list,
>> I was porting some code to Windows and was surprised that a method:
>>    static in __gc(lua_State *L)
>> was using the "__gc" keyword.
>
> If you write your code in compliance with standards, that shouldn't matter.
> Any identifier starting with double underscores is in the purview of the
> implementation, and your code must not define it in any way.

I'm sorry, but I don't understand a single word of this.  Can you
explain with less generalities?  I'm writing strict C++, which I guess
corresponds to "compliance with standards", but I don't follow the
next sentence.

wes

Reply | Threaded
Open this post in threaded view
|

Re: VS2008 and __gc

Stephen Kellett
Wesley Smith wrote:
explain with less generalities?  I'm writing strict C++, which I guess

I don't see how you can be - managed C++ is a special option for Visual Studio .Net variants. My guess is you've wanted to build a version of Lua using Visual Studio and have chosen a default project to then put the various source and header files in, then compile.

That is a fine approach so long as you choose the correct project type. Some project types are for C#, some for VB.Net, some for managed C++, some for C++. If you choose the latter you won't fall over the managed C++ stuff, if you choose the managed C++ options you will.

I'm guessing that you've chosen a C++ project type without realising you've chosen a managed C++ project type. Does that seem feasible?

The syntax of the managed C++ stuff I've seen is quite different (extra keywords to handle use of assemblies etc) to the unmanaged C++ code I normally use.

Stephen

Reply | Threaded
Open this post in threaded view
|

Re: VS2008 and __gc

Chip Salzenberg
In reply to this post by Wesley Smith
On Fri, May 09, 2008 at 11:31:52AM -0700, Wesley Smith wrote:
> On Fri, May 9, 2008 at 11:20 AM, Chip Salzenberg <[hidden email]> wrote:
> > On Fri, May 09, 2008 at 10:06:39AM -0700, Wesley Smith wrote:
> >> Hi list,
> >> I was porting some code to Windows and was surprised that a method:
> >>    static in __gc(lua_State *L)
> >> was using the "__gc" keyword.
> >
> > If you write your code in compliance with standards, that shouldn't matter.
> > Any identifier starting with double underscores is in the purview of the
> > implementation, and your code must not define it in any way.
> 
> I'm sorry, but I don't understand a single word of this.  Can you
> explain with less generalities?  I'm writing strict C++, which I guess
> corresponds to "compliance with standards", but I don't follow the
> next sentence.

You seem not to be obeying the C++ standards.  If you were obeying them,
then you would not be defining a function named "__gc", or any other
identifier that starts with two underscores, and this particular compiler
keyword "__gc" would not disturb you by its existence.
-- 
Chip Salzenberg <[hidden email]>

Reply | Threaded
Open this post in threaded view
|

Re: VS2008 and __gc

Wesley Smith
>> I'm sorry, but I don't understand a single word of this.  Can you
>> explain with less generalities?  I'm writing strict C++, which I guess
>> corresponds to "compliance with standards", but I don't follow the
>> next sentence.
>
> You seem not to be obeying the C++ standards.  If you were obeying them,
> then you would not be defining a function named "__gc", or any other
> identifier that starts with two underscores, and this particular compiler
> keyword "__gc" would not disturb you by its existence.

Is this a C++0x thing?  I use __new, __index, __newindex, __string,
__gc everywhere in my code and GCC has not complained a bit, so I
don't see how this isn't compliant with the C++ standard.  Do you have
documentation of this claim?

wes

Reply | Threaded
Open this post in threaded view
|

Re: VS2008 and __gc

Ben Sunshine-Hill
On Fri, May 9, 2008 at 3:38 PM, Wesley Smith <[hidden email]> wrote:
> Is this a C++0x thing?  I use __new, __index, __newindex, __string,
> __gc everywhere in my code and GCC has not complained a bit, so I
> don't see how this isn't compliant with the C++ standard.  Do you have
> documentation of this claim?

It's in the C++ standard. The precise section is left as an exercise
to the reader.

Reply | Threaded
Open this post in threaded view
|

Re: VS2008 and __gc

James Dennett
In reply to this post by Wesley Smith
On Fri, May 9, 2008 at 12:38 PM, Wesley Smith <[hidden email]> wrote:
> >> I'm sorry, but I don't understand a single word of this.  Can you
>  >> explain with less generalities?  I'm writing strict C++, which I guess
>  >> corresponds to "compliance with standards", but I don't follow the
>  >> next sentence.
>  >
>  > You seem not to be obeying the C++ standards.  If you were obeying them,
>  > then you would not be defining a function named "__gc", or any other
>  > identifier that starts with two underscores, and this particular compiler
>  > keyword "__gc" would not disturb you by its existence.
>
>  Is this a C++0x thing?  I use __new, __index, __newindex, __string,
>  __gc everywhere in my code and GCC has not complained a bit, so I
>  don't see how this isn't compliant with the C++ standard.  Do you have
>  documentation of this claim?

It's in the C++ standard, and commonly documented on the web.

Names containing "__" are reserved for the implementation, in all
contexts.  Compilers can do anything at all with code which uses such
identifiers; you have undefined behavior.  You're stepping on areas
which are for implementors (of C++) only, not for users.

I've a half feeling that recent gcc versions will give warnings/errors
if code outside of system headers/standard library components uses
these names, but I've not checked.

-- James

Reply | Threaded
Open this post in threaded view
|

Re: VS2008 and __gc

Alexander Gladysh
In reply to this post by Wesley Smith
>>> I'm sorry, but I don't understand a single word of this.  Can you
>>> explain with less generalities?  I'm writing strict C++, which I guess
>>> corresponds to "compliance with standards", but I don't follow the
>>> next sentence.
>>
>> You seem not to be obeying the C++ standards.  If you were obeying them,
>> then you would not be defining a function named "__gc", or any other
>> identifier that starts with two underscores, and this particular compiler
>> keyword "__gc" would not disturb you by its existence.
>
> Is this a C++0x thing?  I use __new, __index, __newindex, __string,
> __gc everywhere in my code and GCC has not complained a bit, so I
> don't see how this isn't compliant with the C++ standard.  Do you have
> documentation of this claim?

ISO/IEC 14882:1998(E) (according to Google):

17.4.3.1.2 - Global names [lib.global.names]

-1- Certain sets of names and function signatures are always reserved
to the implementation:

    * Each name that contains a double underscore ("__") or begins
with an underscore followed by an uppercase letter (lex.key) is
reserved to the implementation for any use.

    * Each name that begins with an underscore is reserved to the
implementation for use as a name in the global namespace.*

          [Footnote: Such names are also reserved in namespace ::std
(lib.reserved.names). --- end foonote]


HTH,
Alexander.

Reply | Threaded
Open this post in threaded view
|

Re: VS2008 and __gc

James Dennett
In reply to this post by Ben Sunshine-Hill
On Fri, May 9, 2008 at 12:50 PM, Ben Sunshine-Hill <[hidden email]> wrote:
> On Fri, May 9, 2008 at 3:38 PM, Wesley Smith <[hidden email]> wrote:
>  > Is this a C++0x thing?  I use __new, __index, __newindex, __string,
>  > __gc everywhere in my code and GCC has not complained a bit, so I
>  > don't see how this isn't compliant with the C++ standard.  Do you have
>  > documentation of this claim?
>
>  It's in the C++ standard. The precise section is left as an exercise
>  to the reader.
>

The reader might look for "In addition, some identiïers are reserved
for use by C++ implementations and standard libraries and shall not be
used otherwise; no diagnostic is required" and "Each name that
contains a double underscore _ _ or begins with an underscore followed
by an uppercase letter (2.11) is reserved to the implementation for
any use.".

-- James


Reply | Threaded
Open this post in threaded view
|

Re: VS2008 and __gc

Wesley Smith
Ok,
Thanks for all this info.  For some reason I was under the impression
that __ was a C++0x thing but apparently not.

best,
wes

Reply | Threaded
Open this post in threaded view
|

Re: VS2008 and __gc

Roberto Ierusalimschy
In reply to this post by Alexander Gladysh
> ISO/IEC 14882:1998(E) (according to Google):
> 
> 17.4.3.1.2 - Global names [lib.global.names]
> 
> [...]

As a side note, such names are reserved in ISO C too:

ISO/IEC 9899:1999 (E)   (according to ISO :)

  7.1.3 Reserved identifiers

1 [...]

  â All identifiers that begin with an underscore and either an
  uppercase letter or another underscore are always reserved for any
  use.

  â All identifiers that begin with an underscore are always reserved
  for use as identifiers with file scope in both the ordinary and tag
  name spaces.


-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: VS2008 and __gc

Alexander Gladysh
On Sat, May 10, 2008 at 12:19 AM, Roberto Ierusalimschy
<[hidden email]> wrote:
>> ISO/IEC 14882:1998(E) (according to Google):
>>
>> 17.4.3.1.2 - Global names [lib.global.names]
>>
>> [...]
>
> As a side note, such names are reserved in ISO C too:
>
> ISO/IEC 9899:1999 (E)   (according to ISO :)

Er... I meant that I do not have a copy at hand, and googled up that quote :-)

>
>  7.1.3 Reserved identifiers
>
> 1 [...]
>
>  — All identifiers that begin with an underscore and either an
>  uppercase letter or another underscore are always reserved for any
>  use.
>
>  — All identifiers that begin with an underscore are always reserved
>  for use as identifiers with file scope in both the ordinary and tag
>  name spaces.

Actually, there is a subtle difference. As I understand, plain C
reserves all names at any scope, which begin with undersore or
uppercase letter. C++ reserves global-scope names with leading
underscore, and names in any scope, if such name contain double
underscore at any position.

That is, to write code to be compiled portably both as C and as C++,
one should not use names with leading underscore and should not use
double underscore at all. If some STL implementation choose to define
some internal macro with the same name as yours, you're in trouble.
For  actual life example, see section "Underhanded Names" in Herb
Sutter's GotW #85 (http://www.gotw.ca/gotw/085.htm).

Alexander.


Reply | Threaded
Open this post in threaded view
|

Re: VS2008 and __gc

Roberto Ierusalimschy
> > ISO/IEC 9899:1999 (E)   (according to ISO :)
> 
> Er... I meant that I do not have a copy at hand, and googled up that quote :-)

I understood that. I was just saying that I did have a copy at hand ;-)

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: VS2008 and __gc

Tony Finch
In reply to this post by Alexander Gladysh
On Sat, 10 May 2008, Alexander Gladysh wrote:
>
> Actually, there is a subtle difference. As I understand, plain C
> reserves all names at any scope, which begin with undersore or
> uppercase letter.

No, underscore _followed_by_ an uppercase letter. there are other
restrictions too. See section 7.1.3 of the standard - C99 with technical
corrigenda 1 and 2 can be read at
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf
It says:

Each header declares or defines all identifiers listed in its associated
subclause [i.e. the header's part of section 7], and optionally declares
or defines identifiers listed in its associated future library directions
subclause [i.e. section 7.26] and identifiers which are always reserved
either for any use or for use as file scope identifiers.

—All identifiers that begin with an underscore and either an uppercase
letter or another underscore are always reserved for any use.

—All identifiers that begin with an underscore are always reserved for use
as identifiers with file scope in both the ordinary and tag name spaces.
[i.e. static or global variables and functions, and structure and union tags]

—Each macro name in anyo f the following subclauses (including the future
library directions) is reserved for use as specified if any of its
associated headers is included; unless explicitly stated otherwise (see
7.1.4).

—All identifiers with external linkage in anyo ft he following subclauses
(including the future library directions) are always reserved for use as
identifiers with external linkage. (The list of reserved identifiers with
external linkage includes errno, math_errhandling, setjmp, and va_end.)

—Each identifier with file scope listed in anyo ft he following subclauses
(including the future library directions) is reserved for use as a macro
name and as an identifier with file scope in the same name space if
any of its associated headers is included.

Section 7.26 reserves all external functions that start with is or to or
str or mem or wcs, some of which you might reasonably want to use!

> C++ reserves global-scope names with leading underscore, and names in
> any scope, if such name contain double underscore at any position.

The C++ double underscore restriction is the most obvious extra
restriction compared to C. See section 17.4.3.1 of
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2461.pdf

> That is, to write code to be compiled portably both as C and as C++,
> one should not use names with leading underscore and should not use
> double underscore at all.

Yup.

There's a useful summary of which identifiers to avoid at:
http://web.archive.org/web/20040209031039/http://oakroadsystems.com/tech/c-predef.htm

Tony.
-- 
f.anthony.n.finch  <[hidden email]>  http://dotat.at/
LUNDY FASTNET IRISH SEA SHANNON: VARIABLE MAINLY EAST OR NORTHEAST 3 OR 4.
SLIGHT OR MODERATE. FOG PATCHES. MODERATE OR GOOD, OCCASIONALLY VERY POOR.