CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Jun 2003
    Posts
    53

    compiles in v6, error C2143 in .NET

    The following code compiles in c++ v6, but produces error C1243 in .NET 2003 :-

    typedef __declspec(dllexport) struct flucsLuminaireRecord
    { <<<<<<< error here <<<<<<<<<
    char ID[LUMINAIRENAME];
    char categ[CATEGORY];
    } FlucsLuminaireRecord;

    error C2143: syntax error : missing ';' before '<class-head>'

    Anyone know why?

  2. #2
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: compiles in v6, error C2143 in .NET

    What about this:

    Code:
    __declspec(dllexport) typedef struct flucsLuminaireRecord
    {
       char ID[LUMINAIRENAME];
       char categ[CATEGORY];
    } FlucsLuminaireRecord;
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  3. #3
    Join Date
    Apr 1999
    Posts
    27,449

    Re: compiles in v6, error C2143 in .NET

    Quote Originally Posted by martin_craigen
    The following code compiles in c++ v6,
    No it doesn't. The code you posted as is does not compile in VC 6.0:
    Code:
    typedef __declspec(dllexport) struct flucsLuminaireRecord
    {
        char ID[LUMINAIRENAME];
        char categ[CATEGORY];
    } FlucsLuminaireRecord;
    Compiling...
    test.cpp
    F:\test.cpp(3) : error C2065: 'LUMINAIRENAME' : undeclared identifier
    F:\test.cpp(3) : error C2057: expected constant expression
    F:\test.cpp(3) : warning C4200: nonstandard extension used : zero-sized array in struct/union
    F:\test.cpp(4) : error C2065: 'CATEGORY' : undeclared identifier
    F:\test.cpp(4) : error C2057: expected constant expression
    F:\test.cpp(4) : error C2229: struct 'flucsLuminaireRecord' has an illegal zero-sized array
    F:\test.cpp(4) : warning C4200: nonstandard extension used : zero-sized array in struct/union
    Error executing cl.exe.

    test.obj - 5 error(s), 2 warning(s)
    Please post your entire code. Compiler errors are hard to duplicate if you leave it to us to fill in the blanks.

    Regards,

    Paul McKenzie

  4. #4
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: compiles in v6, error C2143 in .NET

    Of course it doesn't, because you are missing the declarations of LUMINAIRENAME and CATEGORY. If have tried it in VC++ .NET 2k and it compiles fine (with declaring the two identifiers as macros).
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  5. #5
    Join Date
    Apr 1999
    Posts
    27,449

    Re: compiles in v6, error C2143 in .NET

    Quote Originally Posted by NoHero
    Of course it doesn't, because you are missing the declarations of LUMINAIRENAME and CATEGORY. If have tried it in VC++ .NET 2k and it compiles fine (with declaring the two identifiers as macros).
    That is the job of the original poster to put those declarations in their message, so that duplication of the compiler error is done without anyone having to add or remove lines of code.

    By leaving things out, I don't know if this is what is being compiled. Then we must put code in to try and attempt to duplicate the error. By us putting code in, this will skew the results of what the poster is attempting to compile and what someone here has cobbled together. If it compiles fine after placing those two identifiers, then this makes my point. Is this the code that the OP compiling, or is something missing from their original message because they made a typo, they're too hasty and thrown anything together that looks like code, etc.?

    Compiler errors should always be accompanied by the actual code that is being compiled (and I wish this was in the posting FAQ).

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; January 12th, 2005 at 01:48 PM.

  6. #6
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: compiles in v6, error C2143 in .NET

    Of course Paul, you are right. I just wanted to point out, that the syntax of the __declspec() is correct. So he should take a look at the code above. Because I think he is missing a paranthesis or a semicolon after the previous line of code.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  7. #7
    Join Date
    Apr 1999
    Posts
    27,449

    Re: compiles in v6, error C2143 in .NET

    Quote Originally Posted by NoHero
    Of course Paul, you are right. I just wanted to point out, that the syntax of the __declspec() is correct. So he should take a look at the code above. Because I think he is missing a paranthesis or a semicolon after the previous line of code.
    Then this is weird why it would compile for VC 6.0 as the OP stated, since those types of errors (missing a semicolon, etc.) are usually general C++ errors that are picked up by practically every C++ compiler.

    Regards,

    Paul McKenzie

  8. #8
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: compiles in v6, error C2143 in .NET

    Quote Originally Posted by Paul McKenzie
    Then this is weird why it would compile for VC 6.0 as the OP stated, since those types of errors (missing a semicolon, etc.) are usually general C++ errors that are picked up by practically every C++ compiler.

    Regards,

    Paul McKenzie
    It might be a missing semicolon - I don't know of course, because I haven't viewed the code yet - but a missing closing paranthesis is more likely.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  9. #9
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: compiles in v6, error C2143 in .NET

    Quote Originally Posted by martin_craigen
    Anyone know why?

  10. #10
    Join Date
    Jun 2003
    Posts
    53

    Re: compiles in v6, error C2143 in .NET

    OK everyone, thanks for taking the time to help.
    And it did help, because the comments about posting the whole code prompted me to study the code more closely, and ... I found the problem.

    Before posting, I had tried to simplify the post by substituting the macro used to define dllimport/export. It had not dawned on me to check if this was the problem, because the macro is used extensively in the code.

    The original code therefore looked more like

    typedef CLASS_DECL_FLXDB struct flucsLuminaireRecord
    {
    char ID[LUMINAIRENAME];
    char categ[CATEGORY];
    } FlucsLuminaireRecord;

    and CLASS_DECL_FLXDB was set up in another header file as follows :-

    #ifdef FLXDB_IMPL
    #define CLASS_DECL_FLXDB __declspec(dllexport)
    #else
    #define CLASS_DECL_FLXDB __declspec(dllimport)
    #endif

    However, in the code I was trying to compile, this second header file had been REMOVED, so the macro was undefined.

    Apologies to everyone who wasted their time on this. At least I have learned something from it, and that is to double-check my question and ensure it is valid before asking for help from busy people.

  11. #11
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: compiles in v6, error C2143 in .NET

    Quote Originally Posted by martin_craigen
    Apologies to everyone who wasted their time on this. At least I have learned something from it, and that is to double-check my question and ensure it is valid before asking for help from busy people.
    Don't worry....everybody here is always free to answer a question or not....nevertheless, I agree that before posting one should take a the known paths to find the error...

    Have fun with the forums...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured