The Daily WTF: Curious Perversions in Information Technology
Welcome to TDWTF Forums Sign in | Join | Help
in Search

Visual Studio sorta-WTF

Last post 10-30-2007 9:57 AM by aib. 13 replies.
Page 1 of 1 (14 items)
Sort Posts: Previous Next
  • 10-18-2007 1:00 PM

    • krizo
    • Not Ranked
    • Joined on 11-16-2006
    • Posts 5

    Visual Studio sorta-WTF

    I've been working on some new software code at my current job and I keep getting this error:

     error C2059: syntax error : 'constant'

    I looked up the error code on MSDN and got this explanation:

     To determine the cause, examine not only the line listed in the error message, but also the lines above it. 

    ... 

    If examining the lines yields no clue to what the problem might be, try commenting out the line listed in the error message and possibly several lines above it.

     

    Here is the link. 

    I just find it odd that the documentation doesn't really explain what the error is, but how to fix it. It seems like they don't even know what it is.  

    I'm not sure if this is a WTF, but it's certainly frustrating. 

  • 10-18-2007 2:40 PM In reply to

    Re: Visual Studio sorta-WTF

    С2059 is a generic syntax error. It means something like "this (constant) just can't be there!". So you are right, VS doesn't now what's messed up, only that something is.
    ╩юфют√ь ёЄЁрэшЎрь яюЁр эр яхэёш■.

    #TDWTF @ SlashNET was merged into #codelove @ the same network. You're still welcome to drop by. I guess.
  • 10-18-2007 2:41 PM In reply to

    Re: Visual Studio sorta-WTF

    constant as in a const; is that what you're trying to do?
    irc://irc.slashnet.org/#TDWTF (Redirects to #CodeLove )
    Yo dawg I herd hoard you like to search so I put a 2TB txt file in yo SSDS so your memory's maxed out and your computer cant do shit? -- Nyquist
  • 10-20-2007 7:25 AM In reply to

    • aib
    • Top 500 Contributor
    • Joined on 01-03-2007
    • Posts 88

    Re: Visual Studio sorta-WTF

    What I really hate about VS (VC++, actually) is how a code that compiles with no warnings whatsoever (with /Wall) will give you a linker error.

    OK, I may be trying to do my homework (or help with someone else's) without learning all of those fancy namespace/overloading/template rules, but a compiler unable to link my own damn
    function is a WTF!

    I may or may not have meant what I've said above.
  • 10-20-2007 9:00 AM In reply to

    Re: Visual Studio sorta-WTF

    aib:

    What I really hate about VS (VC++, actually) is how a code that compiles with no warnings whatsoever (with /Wall) will give you a linker error.

    OK, I may be trying to do my homework (or help with someone else's) without learning all of those fancy namespace/overloading/template rules, but a compiler unable to link my own damn
    function is a WTF!

    How exactly do you imagine a toolset that can link whatever you give it? A code like this is doomed to compile, but not link:

    int not_defined_anywhere(void);
    int main() { return not_defined_anywhere(); }
    
    ╩юфют√ь ёЄЁрэшЎрь яюЁр эр яхэёш■.

    #TDWTF @ SlashNET was merged into #codelove @ the same network. You're still welcome to drop by. I guess.
  • 10-20-2007 4:45 PM In reply to

    • tster
    • Top 10 Contributor
    • Joined on 04-11-2006
    • Natick, MA
    • Posts 1,764

    Re: Visual Studio sorta-WTF

    aib:

    What I really hate about VS (VC++, actually) is how a code that compiles with no warnings whatsoever (with /Wall) will give you a linker error.

    OK, I may be trying to do my homework (or help with someone else's) without learning all of those fancy namespace/overloading/template rules, but a compiler unable to link my own damn
    function is a WTF!

    You obviously do not understand the purpose of a linker.  The linker is pulling in method definitions from elsewhere to use in your code where you just left method contracts.  If the compiler did what you want then there would be no need for a linker, and the compiler would do everything.  Which would mean that you would have to have all the source code.  Which basically means saying goodbye to most libraries.

    The pig go. Go is to the fountain. The pig put foot. Grunt. Foot in what? ketchup. The dove fly. Fly is in sky. The dove drop something. The something on the pig. The pig disgusting... see bio for the earth shattering ending.
  • 10-21-2007 3:03 PM In reply to

    • aib
    • Top 500 Contributor
    • Joined on 01-03-2007
    • Posts 88

    Re: Visual Studio sorta-WTF

    Err OK, I knew I'd need to clear some things up. Sorry for not taking the time in my previous post.

    First of all, I know what a linker is, thankyouverymuch. And of course I wouldn't expect it to link a nonexistent function. What I meant was more along the lines of:

    int somefunction(void);

    int main(void) { ... somefunction(); ... }

    int somefunction(void) { ... }

    And THEN you have something along the lines of "could not find function 'somefunction' "

     

    Although I've seen quite a few examples (people I've tried to help being unfamiliar with the intricacies of C++, just like myself) in homeworks, etc., I can't find any at the moment. However, rest assured, it would be something along the lines of a class calling a method of another class, all quite properly defined. Because of what I'm guessing some namespace/scope and object code function name generation weirdings, you'd get something like:

    LNKXXX: Unresolved reference to function_name_$$$@@@HASH@@@$$$_wouldreturntypebehere__(__stdio_std::IStream param1, param2, etc.) **

    Sometimes, moving the "using namespace std;" lines around, or even recreating the project with the exact same source files would get rid of the error(s). Mind you, none of the default projects settings would have been modified in the first place.

     

    Call me weird, but I expect proper* code that compiles cleanly to link cleanly.

    *: e.g. one that has all the definitions of all prototyped functions
    **: From what I could gather, the reported name of the missing function would match the name and parameters of the function defined in the sources. For example, function_name() would be able to use param1 without any problems (so we know its type is properly defined). The calling function would not have any problems either; i.e. copy-pasting the contents of function_name() inside the calling function would also work. However, they would just not link.

    Any ideas? 

    I may or may not have meant what I've said above.
  • 10-22-2007 1:04 AM In reply to

    Re: Visual Studio sorta-WTF

    You lack understanding of how C++ name mangling interacts with the linker. It is normal for this sort of problem to be revealed by the linker rather than the compiler.
  • 10-22-2007 9:20 PM In reply to

    • aib
    • Top 500 Contributor
    • Joined on 01-03-2007
    • Posts 88

    Re: Visual Studio sorta-WTF

    asuffield:
    You lack understanding of how C++ name mangling interacts with the linker. It is normal for this sort of problem to be revealed by the linker rather than the compiler.

    ...among many other things. Any pointers?

    I still think it should be the compiler's job to warn me. I mean, both the caller and the function definition itself have the same prototype from the class header?

    From my lacking point of view; I'm either calling a function without a prototype, or I have a prototype without a definition and a definition without a prototype -- both of which should generate a warning.

    I may or may not have meant what I've said above.
  • 10-23-2007 12:37 AM In reply to

    Re: Visual Studio sorta-WTF

    aib:

    asuffield:
    You lack understanding of how C++ name mangling interacts with the linker. It is normal for this sort of problem to be revealed by the linker rather than the compiler.

    ...among many other things. Any pointers?

    It's not something that gets documented. There's no real way to grasp the details other than implementing a C++ compiler.


    I still think it should be the compiler's job to warn me. I mean, both the caller and the function definition itself have the same prototype from the class header?

     

    There's probably a variation in their context. The same sequence of characters can generate a different type in a different context, and as far as C++ is concerned, two functions with different types are unrelated, even if they have the same identifier. The most common scenario is some variation in one of the argument types between the header as included in the definition, and the header as included in the call site, due to inconsistencies in the headers which were included before that point.
  • 10-23-2007 6:27 AM In reply to

    • aib
    • Top 500 Contributor
    • Joined on 01-03-2007
    • Posts 88

    Re: Visual Studio sorta-WTF

    asuffield:

    It's not something that gets documented. There's no real way to grasp the details other than implementing a C++ compiler.

     I thought maybe I could read up on the namespace thing and the scope issues associated with it. (I feel a comment about "any good C++ book" and/or google is on the way; I'll just google it.)


    asuffield:

    There's probably a variation in their context. The same sequence of characters can generate a different type in a different context, and as far as C++ is concerned, two functions with different types are unrelated, even if they have the same identifier. The most common scenario is some variation in one of the argument types between the header as included in the definition, and the header as included in the call site, due to inconsistencies in the headers which were included before that point.

    Yeah that's what I thought it was :/. It was probably due to the IStream/OStream (or their combined class; forgot its name) and something to do with the 'std' namespace. Still, it's freakish when just recreating the project solves the problem.

    Of course, the real WTF is that we had some course/book utility code where .h files included .cpp files...

    I may or may not have meant what I've said above.
  • 10-23-2007 2:07 PM In reply to

    Re: Visual Studio sorta-WTF

    aib:

    Still, it's freakish when just recreating the project solves the problem.

    That's the critical piece of information - what you have is a busted build system (Visual something? It's badly broken), combined with ABI drift. At some point since the last build of the affected files, the relevant types were altered in the source. Only one of the two significant compilation units was recompiled (either implementation or call-site), and the other's out of date, so it failed to link.

  • 10-27-2007 11:27 PM In reply to

    • Daniel15
    • Top 150 Contributor
    • Joined on 01-27-2007
    • Melbourne, Australia
    • Posts 225

    Re: Visual Studio sorta-WTF

    To determine the cause, examine not only the line listed in the error message, but also the lines above it.

    That's classic :P. To me it sounds like "Even though we're saying the error is on this line, it could actually be anywhere above this point. Good luck finding it!"

    Sounds a lot like the Parse error: unexpected $end error in PHP, which most commonly occurs when you forget a closing brace on an if statement or something. The line number it gives you is the very last line of the PHP code, which makes it rather hard to find where the error actually is (you need to check that all brackets and braces are not mismatched)

  • 10-30-2007 9:57 AM In reply to

    • aib
    • Top 500 Contributor
    • Joined on 01-03-2007
    • Posts 88

    Re: Visual Studio sorta-WTF

    asuffield:
    aib:

    Still, it's freakish when just recreating the project solves the problem.

    That's the critical piece of information - what you have is a busted build system (Visual something? It's badly broken), combined with ABI drift. At some point since the last build of the affected files, the relevant types were altered in the source. Only one of the two significant compilation units was recompiled (either implementation or call-site), and the other's out of date, so it failed to link.

    I'm hoping I was stupid enough to forget to clean & rebuild from scratch. Visual C/C++/Studio does that to you...

    I may or may not have meant what I've said above.
Page 1 of 1 (14 items)
Powered by Community Server (Non-Commercial Edition), by Telligent Systems