Thread: gcc is annoying and capricious!

  1. #1
    Registered User BlackOps's Avatar
    Join Date
    Jul 2009
    Location
    AZERBAIJAN
    Posts
    78

    Angry gcc is annoying and capricious!

    I just discover that this gcc compiler is doing strange things... i did something with enum constructor...and i found that programs begin doing strange things after compiling with gcc, i thought i made something wrong...but my code was correct...

    and to show eaxctly... here is very basic code i took from somewhere dealing with enum:

    Code:
    int main (int argc, char *argv[])
    {
      enum planets
      {
        Mercury,
        Venus,
        Earth,
        Mars,
        Jupiter,
        Saturn,
        Uranus,
        Neptune,
        Pluto
      };
    
      enum planets planet1, planet2;
    
      planet1 = Mars;
      planet2 = Earth;
    
      if (planet1 > planet2)
        puts ("Mars is farther from the Sun than Earth is.");
      else
        puts ("Earth is farther from the Sun than Mars is.");
    
        return 0;
    }
    compiles good, no errors, and as u see no errors in the code... however when i run the program, the cursor begins to blink in different places of console window!

    wassup with that? any ideas?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    What do you mean by "different places of console window"? Since you didn't print a new line character, I would expect the cursor to still be on the same line as "Mars is farther from the Sun than Earth is."

  3. #3
    Registered User BlackOps's Avatar
    Join Date
    Jul 2009
    Location
    AZERBAIJAN
    Posts
    78
    no no... it doesnt print this sentence!!

    cursor begins random blinking in the whole screen!

    i tried to compile it with TinyC compiler! and it compiled very good! and program was running good!!!!

    and another thing i compiled for test is this thing:

    printf("%c %c %c\n", *"Foxbat", *("Foxbat" + 1), *("Foxbat" + 2) );

    this line should print: F o x

    however, when i compiled with gcc it gave me an error:

    The NTVDM CPU has encountered an illegal instruction.
    CS:05c3 IP:01............................... etc etc

    when i compiled it with TinyC compiler, it was fine!!! and it printed: F o x

    whats wrong to this gcc?!!?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    I was wrong the first time, since puts put a newline in and I forgot about that.

    The problem here is not gcc -- gcc runs those programs fine. The problem is you+gcc together, or how you are calling gcc, or something similar. What options are you giving gcc?

  5. #5
    Registered User BlackOps's Avatar
    Join Date
    Jul 2009
    Location
    AZERBAIJAN
    Posts
    78
    gcc -o test.exe -c test.c

    and then i call my program as: test


  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by BlackOps View Post
    gcc -o test.exe -c test.c

    and then i call my program as: test

    Since -c means "do not produce an executable file", the odds of you getting an executable file from that command is 0. Leave out the flag if you want an executable file.

  7. #7
    Registered User BlackOps's Avatar
    Join Date
    Jul 2009
    Location
    AZERBAIJAN
    Posts
    78

    Thumbs up

    Great!

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    It produces a .exe alright, except it isn't an executable file!

    Windows being dumb just sees the .exe, loads it into memory and then jumps into it.

    "Mmm, this is a dark and strange place" a few nanoseconds later, and you're looking down the barrel of a segfault or something similar.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed