Really easy cygwin / gcc question

Discussion in 'C Programming' started by Michael, May 30, 2006.

  1. Michael

    Michael Guest

    Hi All,

    Why when I complile and run the following:

    #include "stdio.h"
    main(void)
    {
    printf("test test test\n");
    }

    do I get no output to the screen? If I run it in the ddd debugger I get the
    'test test test' in the console window, but when I run it from an Xterm get
    nothing. Im wondering if stdout is set to somewhere else, but how do I check
    this?

    Regards
    Michael
    Michael, May 30, 2006
    #1
    1. Advertising

  2. Michael

    Vladimir Oka Guest

    Michael wrote:
    > Hi All,
    >
    > Why when I complile and run the following:
    >
    > #include "stdio.h"
    > main(void)
    > {
    > printf("test test test\n");
    > }
    >
    > do I get no output to the screen? If I run it in the ddd debugger I get the
    > 'test test test' in the console window, but when I run it from an Xterm get
    > nothing. Im wondering if stdout is set to somewhere else, but how do I check
    > this?


    Your program should output "test test test" as you expect. The only
    problem you have is that pre-C99 you need to return something from
    `main()`. You don't tell what options you passed to your compiler and
    what warnings, if any, you get.
    Vladimir Oka, May 30, 2006
    #2
    1. Advertising

  3. Michael

    Vladimir Oka Guest

    Vladimir Oka wrote:
    > Michael wrote:
    > > Hi All,
    > >
    > > Why when I complile and run the following:
    > >
    > > #include "stdio.h"
    > > main(void)
    > > {
    > > printf("test test test\n");
    > > }
    > >
    > > do I get no output to the screen? If I run it in the ddd debugger I get the
    > > 'test test test' in the console window, but when I run it from an Xterm get
    > > nothing. Im wondering if stdout is set to somewhere else, but how do I check
    > > this?

    >
    > Your program should output "test test test" as you expect. The only
    > problem you have is that pre-C99 you need to return something from
    > `main()`. You don't tell what options you passed to your compiler and
    > what warnings, if any, you get.


    PS
    You should also avoid implicit `int` when declaring `main()`. Spell it
    out:

    int main(void)
    Vladimir Oka, May 30, 2006
    #3
  4. Michael

    Michael Guest

    Hi Vladimir,

    I just used:
    gcc -g test.c -o test.exe

    I get no warnings or errors

    Thanks for your help.

    Regards
    Michael
    "Vladimir Oka" <> wrote in message
    news:...
    >
    > Michael wrote:
    >> Hi All,
    >>
    >> Why when I complile and run the following:
    >>
    >> #include "stdio.h"
    >> main(void)
    >> {
    >> printf("test test test\n");
    >> }
    >>
    >> do I get no output to the screen? If I run it in the ddd debugger I get
    >> the
    >> 'test test test' in the console window, but when I run it from an Xterm
    >> get
    >> nothing. Im wondering if stdout is set to somewhere else, but how do I
    >> check
    >> this?

    >
    > Your program should output "test test test" as you expect. The only
    > problem you have is that pre-C99 you need to return something from
    > `main()`. You don't tell what options you passed to your compiler and
    > what warnings, if any, you get.
    >
    Michael, May 30, 2006
    #4
  5. Michael

    Richard Bos Guest

    "Michael" <> wrote:

    > Why when I complile and run the following:
    >
    > #include "stdio.h"
    > main(void)
    > {
    > printf("test test test\n");
    > }
    >
    > do I get no output to the screen? If I run it in the ddd debugger I get the
    > 'test test test' in the console window, but when I run it from an Xterm get
    > nothing. Im wondering if stdout is set to somewhere else, but how do I check
    > this?


    You have a problem with your compiler setup. When I run this from the
    compiler, I get a window that flashes on the screen and disappears
    (which I can prevent by adding a command that makes it wait for input,
    naturally); when I run it from a command line, it works as it should.

    Ask in a newsgroup dedicated to your specific compiler suite or OS.

    Richard
    Richard Bos, May 30, 2006
    #5
  6. Michael

    Flash Gordon Guest

    Michael wrote:

    Your response belongs *under* the text you are replying to, after
    deleting bits you are not replying to, not above. I've corrected it this
    time.

    > "Vladimir Oka" <> wrote in message
    > news:...
    >> Michael wrote:
    >>> Hi All,
    >>>
    >>> Why when I complile and run the following:
    >>>
    >>> #include "stdio.h"
    >>> main(void)
    >>> {
    >>> printf("test test test\n");
    >>> }
    >>>
    >>> do I get no output to the screen? If I run it in the ddd debugger I get
    >>> the
    >>> 'test test test' in the console window, but when I run it from an Xterm
    >>> get
    >>> nothing. Im wondering if stdout is set to somewhere else, but how do I
    >>> check
    >>> this?

    >> Your program should output "test test test" as you expect. The only
    >> problem you have is that pre-C99 you need to return something from
    >> `main()`. You don't tell what options you passed to your compiler and
    >> what warnings, if any, you get.


    And, as you point out in another message, you should not use implicit
    int ;-)

    > Hi Vladimir,
    >
    > I just used:
    > gcc -g test.c -o test.exe
    >
    > I get no warnings or errors


    OK, first off you are not doing enough to get all the useful warnings.
    You should add -ansi -pedantic -Wall -O
    Possibly -W as well, depending on your preferences.

    Secondly, under C89 the compiler is not required to complain about
    anything in your code (under C99, the latest standard not commonly
    implemented the compiler is required to complain about the implicit
    int), so the lack of warnings is not surprising.

    <OT>
    bash has a built in command called test so it will be running that
    rather than your program. Just rename your program and it should work.
    </OT>

    PS, OT means Off Topic, i.e. if you want to discuss bash and its built
    in test command further this is not the correct place.
    --
    Flash Gordon, living in interesting times.
    Web site - http://home.flash-gordon.me.uk/
    comp.lang.c posting guidelines and intro:
    http://clc-wiki.net/wiki/Intro_to_clc
    Flash Gordon, May 30, 2006
    #6
  7. Michael wrote:
    > I just used:
    > gcc -g test.c -o test.exe
    >

    Never name a test script or program "test" in any POSIX environment.
    The shell builtin will usually be found first, and your program will
    never be found.

    Use "foo" for test programs. It's why the gods created that word.
    Clever Monkey, May 30, 2006
    #7
  8. Flash Gordon wrote:
    > Michael wrote:

    -snip-

    > > Hi Vladimir,
    > >
    > > I just used:
    > > gcc -g test.c -o test.exe
    > >
    > > I get no warnings or errors

    >
    > OK, first off you are not doing enough to get all the useful warnings.
    > You should add -ansi -pedantic -Wall -O
    > Possibly -W as well, depending on your preferences.


    I couldn't find any information on -W. I thought -Wall was the highest
    warning level. What would -W do?


    Best regards
    Martin Jørgensen

    --
    ---------------------------------------------------------------------------
    Home of Martin Jørgensen - http://www.martinjoergensen.dk
    =?ISO-8859-1?Q?Martin_J=F8rgensen?=, May 30, 2006
    #8
  9. Michael

    Default User Guest

    Michael wrote:

    > Hi Vladimir,
    >
    > I just used:
    > gcc -g test.c -o test.exe
    >
    > I get no warnings or errors
    >
    > Thanks for your help.


    Don't top-post. Your replies belong following or interspersed with the
    quotes.

    As one person already mentioned, there is a progam called "test" on
    most UNIX systems. Also, if you're running from the CYGWIN shell you
    can't leave off the extension when you run it the way you can with
    Windows or DOS. That's why progams developed on UNIX systems tend not
    to have the .exe extension, as it doesn't mean (or do) anything special.





    Brian
    Default User, May 30, 2006
    #9
  10. Michael

    Flash Gordon Guest

    Martin Jørgensen wrote:
    > Flash Gordon wrote:
    >> Michael wrote:

    > -snip-
    >
    >> > Hi Vladimir,
    >> >
    >> > I just used:
    >> > gcc -g test.c -o test.exe
    >> >
    >> > I get no warnings or errors

    >>
    >> OK, first off you are not doing enough to get all the useful warnings.
    >> You should add -ansi -pedantic -Wall -O
    >> Possibly -W as well, depending on your preferences.

    >
    > I couldn't find any information on -W. I thought -Wall was the highest
    > warning level. What would -W do?


    It enables more warnings. Ask on one og the GNU gcc groups for more
    information, such as gnu.gcc.help remembering to tell them what version
    of gcc you are using.
    --
    Flash Gordon, living in interesting times.
    Web site - http://home.flash-gordon.me.uk/
    comp.lang.c posting guidelines and intro:
    http://clc-wiki.net/wiki/Intro_to_clc
    Flash Gordon, May 30, 2006
    #10
  11. Martin Jørgensen <> writes:
    > Flash Gordon wrote:
    >> Michael wrote:

    > -snip-
    >
    >> > Hi Vladimir,
    >> >
    >> > I just used:
    >> > gcc -g test.c -o test.exe
    >> >
    >> > I get no warnings or errors

    >> OK, first off you are not doing enough to get all the useful
    >> warnings. You should add -ansi -pedantic -Wall -O
    >> Possibly -W as well, depending on your preferences.

    >
    > I couldn't find any information on -W. I thought -Wall was the highest
    > warning level. What would -W do?


    <OT>
    "info gcc" should show you the documentation for gcc, including
    descriptions of all the command-line options.
    </OT>

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, May 30, 2006
    #11
  12. Clever Monkey <> writes:
    > Michael wrote:
    >> I just used:
    >> gcc -g test.c -o test.exe
    >>

    > Never name a test script or program "test" in any POSIX
    > environment. The shell builtin will usually be found first, and your
    > program will never be found.
    >
    > Use "foo" for test programs. It's why the gods created that word.


    <WAY_OT>
    Better yet, never included "." (the current directory) in your $PATH.
    If you want to execute a program in your current directory, always
    type "./whatever".
    </WAY_OT>

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, May 30, 2006
    #12
  13. Martin Jørgensen said:

    > I couldn't find any information on -W. I thought -Wall was the highest
    > warning level. What would -W do?


    Not enough. Give yourself nightmares with -W -Wall -ansi -pedantic
    -Wformat-nonliteral -Wcast-align -Wpointer-arith -Wbad-function-cast
    -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Winline
    -Wundef -Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings
    -Wno-conversion -ffloat-store -O2

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
    Richard Heathfield, May 30, 2006
    #13
  14. "Default User" <> writes:
    > Michael wrote:
    >
    >> Hi Vladimir,
    >>
    >> I just used:
    >> gcc -g test.c -o test.exe
    >>
    >> I get no warnings or errors
    >>
    >> Thanks for your help.

    >
    > Don't top-post. Your replies belong following or interspersed with the
    > quotes.
    >
    > As one person already mentioned, there is a progam called "test" on
    > most UNIX systems. Also, if you're running from the CYGWIN shell you
    > can't leave off the extension when you run it the way you can with
    > Windows or DOS. That's why progams developed on UNIX systems tend not
    > to have the .exe extension, as it doesn't mean (or do) anything special.


    <WAY_OT>
    Cygwin runs under Windows, so executables always have names ending in
    ".exe". You can omit the extension when you execute the program;
    Cygwin does some magic to let you refer to the file as either "foo" or
    "foo.exe". If there's a shell script called "foo" and an executable
    called "foo.exe", it resolves the ambiguity in some manner that I
    can't be bothered to remember.
    </WAY_OT>

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, May 30, 2006
    #14
  15. Michael

    Default User Guest

    Keith Thompson wrote:

    > "Default User" <> writes:


    > > As one person already mentioned, there is a progam called "test" on
    > > most UNIX systems. Also, if you're running from the CYGWIN shell you
    > > can't leave off the extension when you run it the way you can with
    > > Windows or DOS. That's why progams developed on UNIX systems tend
    > > not to have the .exe extension, as it doesn't mean (or do) anything
    > > special.

    >
    > <WAY_OT>
    > Cygwin runs under Windows, so executables always have names ending in
    > ".exe". You can omit the extension when you execute the program;
    > Cygwin does some magic to let you refer to the file as either "foo" or
    > "foo.exe". If there's a shell script called "foo" and an executable
    > called "foo.exe", it resolves the ambiguity in some manner that I
    > can't be bothered to remember.
    > </WAY_OT>


    Ah. I thought it pretty much ran whatever shell it was, and the usual
    Windows rules wouldn't come into play. I'm pretty sure it's at least
    case-sensitive.



    Brian

    --
    Please quote enough of the previous message for context. To do so from
    Google, click "show options" and use the Reply shown in the expanded
    header.
    Default User, May 30, 2006
    #15
  16. "Default User" <> writes:
    > [A cygwin question]


    I'll reply to this by e-mail.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, May 31, 2006
    #16
  17. Michael

    Michael Guest

    "Flash Gordon" <> wrote in message
    news:-gordon.me.uk...
    > Michael wrote:
    >
    > Your response belongs *under* the text you are replying to, after deleting
    > bits you are not replying to, not above. I've corrected it this time.
    >
    >> "Vladimir Oka" <> wrote in message
    >> news:...
    >>> Michael wrote:
    >>>> Hi All,
    >>>>
    >>>> Why when I complile and run the following:
    >>>>
    >>>> #include "stdio.h"
    >>>> main(void)
    >>>> {
    >>>> printf("test test test\n");
    >>>> }
    >>>>
    >>>> do I get no output to the screen? If I run it in the ddd debugger I get
    >>>> the
    >>>> 'test test test' in the console window, but when I run it from an Xterm
    >>>> get
    >>>> nothing. Im wondering if stdout is set to somewhere else, but how do I
    >>>> check
    >>>> this?
    >>> Your program should output "test test test" as you expect. The only
    >>> problem you have is that pre-C99 you need to return something from
    >>> `main()`. You don't tell what options you passed to your compiler and
    >>> what warnings, if any, you get.

    >
    > And, as you point out in another message, you should not use implicit int
    > ;-)
    >
    > > Hi Vladimir,
    > >
    > > I just used:
    > > gcc -g test.c -o test.exe
    > >
    > > I get no warnings or errors

    >
    > OK, first off you are not doing enough to get all the useful warnings. You
    > should add -ansi -pedantic -Wall -O
    > Possibly -W as well, depending on your preferences.
    >
    > Secondly, under C89 the compiler is not required to complain about
    > anything in your code (under C99, the latest standard not commonly
    > implemented the compiler is required to complain about the implicit int),
    > so the lack of warnings is not surprising.
    >
    > <OT>
    > bash has a built in command called test so it will be running that rather
    > than your program. Just rename your program and it should work.
    > </OT>
    >
    > PS, OT means Off Topic, i.e. if you want to discuss bash and its built in
    > test command further this is not the correct place.
    > --


    Thanks Guys, I knew it would be something really easy :)
    Michael, May 31, 2006
    #17
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    415
  2. Replies:
    0
    Views:
    417
  3. WELCOME to

    , Sep 3, 2003, in forum: Python
    Replies:
    1
    Views:
    502
    Robin Becker
    Sep 5, 2003
  4. Replies:
    0
    Views:
    401
  5. =?Utf-8?B?TFc=?=
    Replies:
    8
    Views:
    397
    =?Utf-8?B?TFc=?=
    Apr 25, 2007
Loading...

Share This Page