Thread: Advanced C Question: #line and #ifndef stuff

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    167

    Advanced C Question: #line and #ifndef stuff

    All source code is available at: http://www.cs.ucsb.edu/~cs165a/software.html

    I'm trying to compile http://www.cs.ucsb.edu/~cs165a/Softw...c/CNFDemo.html

    Files I'm using (all available in the zip file):

    CNFDemo.cpp

    KnowledgeBase.cpp
    KnowledgeBase.h

    parser.cpp
    parser.h

    lex.yy.cpp (commented out #include <unistd.h> because the file is blank anyway)
    y.tab.cpp
    y.tab.h

    I'm having a lot of trouble getting the program to run. So far I've figured out it's because of the #line funny business going on in y.tab.cpp. It runs up to a certain point and then just quits unexpectedly (Visual Studio says "there is no source code for the following line). So I commented out a lot of that stuff and now it runs a bit farther. But it still just stops randomly.

    Can anyone get this program to compile?
    Last edited by Paul22000; 11-10-2008 at 12:51 AM.

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    167
    Alright, I've figured out the exact line where it stops, here's a picture:

    http://img20.imageshack.us/img20/438...cecode2sd7.png

    I can run up to the line with the breakpoint. I press run line once and it dies.

    Does anyone know why this is happening?

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    167
    Ah it seems "yyn" is not defined anywhere. So how the hell does this crap compile but not run?

    Man, who coded this pos...

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    What moron coded this I would ask? I see gotos.
    And it is C++, btw, not C.
    But the "no source code" thingy just means that the debugger cannot find the source for that specific part of the code, not that it does not exist or does not run. You should make sure you compile and create symbols for the code and the debugger should work correctly.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    167
    Quote Originally Posted by Elysia View Post
    What moron coded this I would ask? I see gotos.
    That's what I was wondering =\

    This is the "AI Library" that the professor wants us to use for our programs. Sure, it makes certain aspects easier for coding other AI programs, but man, some of this crap is coded like absolute hell...

    But the "no source code" thingy just means that the debugger cannot find the source for that specific part of the code, not that it does not exist or does not run. You should make sure you compile and create symbols for the code and the debugger should work correctly.
    How do you compile and create symbols for the code?

    I am using both Visual Studio Express in Windows and gcc in Unix. Both give massive amounts of linker errors. But with Windows I've seemed to fix those, and now just get the "cannot find source code".

    Were you able to get it to compile? Or have any ideas? I'm at a loss, I've never seen gotos and all that =\

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Usually "no source code" means that you are inside a DLL or library function that you haven't got source code for. If you have the source for the library, you can recompile with debug settings, but likely is that you do not have the source code for the library or DLL, in which case it's "tough luck". But usually, you can get a call-stack and figure out from that where your problem stems from.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Apr 2008
    Posts
    167
    Quote Originally Posted by matsp View Post
    Usually "no source code" means that you are inside a DLL or library function that you haven't got source code for. If you have the source for the library, you can recompile with debug settings, but likely is that you do not have the source code for the library or DLL, in which case it's "tough luck". But usually, you can get a call-stack and figure out from that where your problem stems from.

    --
    Mats
    How do I recompile with debug settings?

    Or get the call-stack?

    I'm sure this *has* to compile somehow. It's a library; whoever made it wouldn't put out a broken library.

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Dude, we're telling you - it IS compiled, there is nothing wrong with it. You simply lack debug information about it.
    To compile as Debug, you would choose Debug from the drop-down list which typically says Release or Debug.
    The call-stack is a window at the bottom of the IDE, which displays the entire call stack so far.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Note however that just because you compile the library YOU are using, doesn't mean that other libraries aren't being used, and you may not have access to the source-code that is failing. Let's say we write some stupid code like this:
    Code:
    ...
    FILE *f = (FILE *)12345678;
    
    fprintf(f, "Hello, world\n");
    then the crash would happen in fprintf() - you may not have source code for fprintf() [or debug symbols for the C runtime library that has the function in it]. But using the call-stack window to find the call to fprintf, you may be able to figure out what is being done.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Registered User
    Join Date
    Apr 2008
    Posts
    167
    Quote Originally Posted by Elysia View Post
    Dude, we're telling you - it IS compiled, there is nothing wrong with it. You simply lack debug information about it.
    To compile as Debug, you would choose Debug from the drop-down list which typically says Release or Debug.
    The call-stack is a window at the bottom of the IDE, which displays the entire call stack so far.
    I'm not sure I follow? If I hit run, the program quits without getting past the first line of main.

    Were you able to get CNFDemo.cpp to run to the end?
    Last edited by Paul22000; 11-10-2008 at 10:33 AM.

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Paul22000 View Post
    I'm not sure I follow? If I hit run, the program quits without getting past the first line of main.
    If the code is not compiled, then you cannot debug it and obviously you were debugging it, so the code is compiled.
    If it works correctly, without bugs and so, is another story.

    Were you able to get CNFDemo.cpp to run to the end?
    Unfortunately not, because this seemed like some "multi-platform" crap (sorry for saying so). They always make it difficult to get the thing compiled or whatever. I'm not up for the task.
    I just want a visual studio project to launch up and compile. But there was no such thing, was there (or did I miss it because of the Linux-style readme files?)?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Registered User
    Join Date
    Apr 2008
    Posts
    167
    If the code is not compiled, then you cannot debug it and obviously you were debugging it, so the code is compiled.
    If it works correctly, without bugs and so, is another story.
    Ah, I see what you mean. Yes, it does compile without errors. That part is ok. However, it doesn't run.

    I just want a visual studio project to launch up and compile. But there was no such thing, was there (or did I miss it because of the Linux-style readme files?)?
    Ah, great idea! Here's the code and the Visual Studio Express in one nice neat package

    http://www.speedyshare.com/533573179.html

    I'll be working on it all this morning (and watching this thread) if you or anyone else have any ideas

  13. #13
    Registered User
    Join Date
    Apr 2008
    Posts
    167
    Figured out all that yy crap has to do with some stupid Bison library. The coding is just god-awful though. #defines and #if's all over the place =\

  14. #14
    Registered User
    Join Date
    Apr 2008
    Posts
    167
    Quote Originally Posted by matsp View Post
    Note however that just because you compile the library YOU are using, doesn't mean that other libraries aren't being used, and you may not have access to the source-code that is failing. Let's say we write some stupid code like this:
    Code:
    ...
    FILE *f = (FILE *)12345678;
    
    fprintf(f, "Hello, world\n");
    then the crash would happen in fprintf() - you may not have source code for fprintf() [or debug symbols for the C runtime library that has the function in it]. But using the call-stack window to find the call to fprintf, you may be able to figure out what is being done.

    --
    Mats
    Here's a picture of the call-stack:

    http://img114.imageshack.us/img114/3...llstackxh8.png

    The line that it's paused at is the exact line that causes the error.

    I guess I've stumped everyone?

  15. #15
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Actually, Bison is a dialect of Yacc, which is a "compiler compiler" - a tool that takes a "human" readable input and produces C code to parse "code". The yy-stuff is not a stupid library, but a result of the Bison (or Yacc - that's why it's "yy") reading it's input file.

    Yacc/Bison is often used in conjunction with (f)lex.

    Have you actually asked your teacher if this code is supposed to work, as I expect you aren't supposed to work in teh Yacc code, but rather use the source code for AI programming?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can some one please tell me the cause of the error ?
    By broli86 in forum C Programming
    Replies: 8
    Last Post: 06-26-2008, 08:36 PM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  3. Warning on an ifndef directive
    By DavidP in forum C++ Programming
    Replies: 2
    Last Post: 08-02-2007, 01:31 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM