Really easy cygwin / gcc question

M

Michael

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
 
V

Vladimir Oka

Michael said:
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.
 
V

Vladimir Oka

Vladimir said:
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)
 
M

Michael

Hi Vladimir,

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

I get no warnings or errors

Thanks for your help.

Regards
Michael
 
R

Richard Bos

Michael said:
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
 
F

Flash Gordon

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.

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.
 
C

Clever Monkey

Michael said:
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.
 
?

=?ISO-8859-1?Q?Martin_J=F8rgensen?=

Flash said:
Michael wrote: -snip-


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
 
D

Default User

Michael said:
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
 
F

Flash Gordon

Martin said:
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.
 
K

Keith Thompson

Martin Jørgensen said:
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>
 
K

Keith Thompson

Clever Monkey said:
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>
 
R

Richard Heathfield

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
 
K

Keith Thompson

Default User said:
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>
 
D

Default User

Keith said:
<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
 
M

Michael

Flash Gordon said:
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.


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


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 :)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top