Re: [Mingw-w64-public] fork is an inbuilt function?

2014-07-24 Thread Óscar Fuentes
"lh_mouse" writes:

> EDIT: since C99, reaching the } that terminates the main function returns a 
> value of 0.
>
> 'The returned value is undefined' is not true. If the return value is used(in 
> the case of main(),
> the host environment cares about it),

I already said that undefined behavior arises if the returned value is used.

OTOH, do yo know an environment where the exit code of an application is
relevant for a toy program when executed from a shell?

> you get undefined behavior and give the compiler and runtime
> the right to do whatever they want to do including invoking something
> like rm -rf /.

I'm a bit tired of that hyperbole. In this case it is even more absurd
than usual. You are effectively saying that returning certain values
from main would cause the runtime to do very bad things. Such an
environment is tragically broken, obviously.

BTW, you can be pretty sure that every large C/C++ application you use
contains cases of undefined behavior. Do you backup your hard disk and
disconnect from the internet before executing them? :-)

> Since gcc uses -std=gnu89 by default, it is not safe to omit return 0; in 
> main().
>
> ISO/IEC 9899:201X Programming languages — C
> 6.9.1 Function definitions
> 12 If the } that terminates a function is reached, and the value of the 
> function call is used by
> the caller, the behavior is undefined.

Curious. On my copy of ISO/IEC 9899 6.9 is "Future language directions"
and 6.9.1 is "External names".

In 6.7.1 "Function definitions" I see nothing relevant.

In "The ANSI C Programming Language", page 203, it is said:

"Flowing off the end of a function is equivalent to a return with no
expression. In either case, the return value is undefined."


--
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] fork is an inbuilt function?

2014-07-23 Thread lh_mouse
EDIT: since C99, reaching the } that terminates the main function returns a 
value of 0.

'The returned value is undefined' is not true. If the return value is used(in 
the case of main(),
the host environment cares about it), you get undefined behavior and give the 
compiler and runtime
the right to do whatever they want to do including invoking something like rm 
-rf /.
Since gcc uses -std=gnu89 by default, it is not safe to omit return 0; in 
main().

ISO/IEC 9899:201X Programming languages — C
6.9.1 Function definitions
12 If the } that terminates a function is reached, and the value of the 
function call is used by
the caller, the behavior is undefined.

--   
Best regards,
lh_mouse
2014-07-24

-
发件人:Óscar Fuentes 
发送日期:2014-07-24 10:52
收件人:mingw-w64-public
抄送:
主题:Re: [Mingw-w64-public] fork is an inbuilt function?

Apart from what lh_mouse says about C++, in C if your function is
declared to return an int and there is no return statement the returned
value is undefined (not to be confused with undefined behavior, which
only happens on this case if you *use* the value returned by that
function.)

So you can omit the return at the end of `main' on your toy C program
unless you plan to use the process' exit value.


--
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] fork is an inbuilt function?

2014-07-23 Thread Óscar Fuentes
Suresh Govindachar
 writes:

>>  > This isn't the first time you corrected me on the return value from
>>  > main when I'm making a test-case to demonstrate a compiler issue; I
>>  > honestly couldn't care less and my goal is to use the minimum amount
>>  > of characters and so following the standards doesn't come into it,
>>
>> `int' is one character less than `void' ;-)
>>
>>
>> I was just about to write that :-P
>
> Well, I too was about to write that -- but didn't since with an int 
> return the body of main would need to change too, wouldn't it?
>
> Compare:
>void main(){}
> with
>int main(){ return 0;} // perhaps return is not needed?
>
> (I don't mind typing!)

Apart from what lh_mouse says about C++, in C if your function is
declared to return an int and there is no return statement the returned
value is undefined (not to be confused with undefined behavior, which
only happens on this case if you *use* the value returned by that
function.)

So you can omit the return at the end of `main' on your toy C program
unless you plan to use the process' exit value.


--
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] fork is an inbuilt function?

2014-07-23 Thread lh_mouse
You can omit return 0; in main() in C++ only.

ISO/IEC 14882 Programming languages -- C++
3.6.1 Main function [basic.start.main]
5 ... If control reaches the end of main without encountering
a return statement, the effect is that of executing
return 0;

--   
Best regards,
lh_mouse
2014-07-24

-
发件人:Suresh Govindachar 
发送日期:2014-07-24 09:53
收件人:mingw-w64-public
抄送:
主题:Re: [Mingw-w64-public] fork is an inbuilt function?

Well, I too was about to write that -- but didn't since with an int 
return the body of main would need to change too, wouldn't it?

Compare:
   void main(){}
with
   int main(){ return 0;} // perhaps return is not needed?


--
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] fork is an inbuilt function?

2014-07-23 Thread Suresh Govindachar
On 7/23/2014 4:39 AM, Ruben Van Boxem wrote:
> 2014-07-23 13:32 GMT+02:00 Óscar Fuentes  >:
>
> Ray Donnelly mailto:mingw.andr...@gmail.com>>
> writes:
>
>  > Hi Ruben,
>  >
>  > Please take this in the friendly/jokey manner it is intended.
>  >
>  > This isn't the first time you corrected me on the return value from
>  > main when I'm making a test-case to demonstrate a compiler issue; I
>  > honestly couldn't care less and my goal is to use the minimum amount
>  > of characters and so following the standards doesn't come into it,
>
> `int' is one character less than `void' ;-)
>
>
> I was just about to write that :-P

Well, I too was about to write that -- but didn't since with an int 
return the body of main would need to change too, wouldn't it?

Compare:
   void main(){}
with
   int main(){ return 0;} // perhaps return is not needed?

(I don't mind typing!)

>  > but
>  > if you feel you must point this out each time, I'll just consider
> it a
>  > quirk and ignore it.
>
> I would do the same as Ruben. When I contribute help on a public mailing
> list, my message is not directed at the individual who asked, but to
> every potential reader, current or future.
>
> Whenever you post an incorrect piece of code, think that all sorts of
> users will read your message, including newbies that can "learn" by
> reading your posts. Hence, Ruben is counterbalancing your misinformation
> :-)
>
>
> Yeah, it's a positive side effect of me spending too much time on
> stackoverflow.com . I start spotting mistakes
> all over the place :-)
>
> (Thanks for the backup!)
>
> Ruben
>
>
> [snip]
>


--
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] fork is an inbuilt function?

2014-07-23 Thread Ruben Van Boxem
2014-07-23 13:32 GMT+02:00 Óscar Fuentes :

> Ray Donnelly 
> writes:
>
> > Hi Ruben,
> >
> > Please take this in the friendly/jokey manner it is intended.
> >
> > This isn't the first time you corrected me on the return value from
> > main when I'm making a test-case to demonstrate a compiler issue; I
> > honestly couldn't care less and my goal is to use the minimum amount
> > of characters and so following the standards doesn't come into it,
>
> `int' is one character less than `void' ;-)
>

I was just about to write that :-P

>
> > but
> > if you feel you must point this out each time, I'll just consider it a
> > quirk and ignore it.
>
> I would do the same as Ruben. When I contribute help on a public mailing
> list, my message is not directed at the individual who asked, but to
> every potential reader, current or future.
>
> Whenever you post an incorrect piece of code, think that all sorts of
> users will read your message, including newbies that can "learn" by
> reading your posts. Hence, Ruben is counterbalancing your misinformation
> :-)
>

Yeah, it's a positive side effect of me spending too much time on
stackoverflow.com. I start spotting mistakes all over the place :-)

(Thanks for the backup!)

Ruben


>
> [snip]
>
>
>
> --
> Want fast and easy access to all the code in your enterprise? Index and
> search up to 200,000 lines of code with a free copy of Black Duck
> Code Sight - the same software that powers the world's largest code
> search on Ohloh, the Black Duck Open Hub! Try it now.
> http://p.sf.net/sfu/bds
> ___
> Mingw-w64-public mailing list
> Mingw-w64-public@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
>
--
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] fork is an inbuilt function?

2014-07-23 Thread Óscar Fuentes
Ray Donnelly 
writes:

> Hi Ruben,
>
> Please take this in the friendly/jokey manner it is intended.
>
> This isn't the first time you corrected me on the return value from
> main when I'm making a test-case to demonstrate a compiler issue; I
> honestly couldn't care less and my goal is to use the minimum amount
> of characters and so following the standards doesn't come into it,

`int' is one character less than `void' ;-)

> but
> if you feel you must point this out each time, I'll just consider it a
> quirk and ignore it.

I would do the same as Ruben. When I contribute help on a public mailing
list, my message is not directed at the individual who asked, but to
every potential reader, current or future.

Whenever you post an incorrect piece of code, think that all sorts of
users will read your message, including newbies that can "learn" by
reading your posts. Hence, Ruben is counterbalancing your misinformation
:-)

[snip]


--
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] fork is an inbuilt function?

2014-07-23 Thread Ray Donnelly
Hi Ruben,

Please take this in the friendly/jokey manner it is intended.

This isn't the first time you corrected me on the return value from
main when I'm making a test-case to demonstrate a compiler issue; I
honestly couldn't care less and my goal is to use the minimum amount
of characters and so following the standards doesn't come into it, but
if you feel you must point this out each time, I'll just consider it a
quirk and ignore it.

You are right, we should file it with GCC, but maybe I'll just look
into it an patch it.

--
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] fork is an inbuilt function?

2014-07-23 Thread Ruben Van Boxem
2014-07-22 23:37 GMT+02:00 Ray Donnelly :

> Hello,
>
> While porting msysGit to MSYS2/MinGW-w64 we ran into this:
>
> $ PATH=/mingw64/bin:"$PATH" gcc --version
> gcc.exe (Rev1, Built by MSYS2 project) 4.9.1
>
> $ cat test.c
> #include 
> static inline pid_t fork(void);
> void main() {}
>
> $ PATH=/mingw64/bin:"$PATH" gcc test.c
> test.c:2:21: warning: conflicting types for built-in function 'fork'
>  static inline pid_t fork(void);
>  ^
>
> Anyone got any ideas about this?
>

GCC has a number of builtin functions like printf, memcpy, and a bunch of
math functions as well. This is mostly for optimization  It seems it also
has a builtin "fork", which it really should disable for Windows targets,
but doesn't. I'd file a bug report, GCC shouldn't have a builtin fork on
Windows.

Also note that main should return int, not void. The latter is technically
undefined behavior.

Cheers,

Ruben


> Best regards,
>
> Ray.
>
>
> --
> Want fast and easy access to all the code in your enterprise? Index and
> search up to 200,000 lines of code with a free copy of Black Duck
> Code Sight - the same software that powers the world's largest code
> search on Ohloh, the Black Duck Open Hub! Try it now.
> http://p.sf.net/sfu/bds
> ___
> Mingw-w64-public mailing list
> Mingw-w64-public@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
>
--
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


[Mingw-w64-public] fork is an inbuilt function?

2014-07-22 Thread Ray Donnelly
Hello,

While porting msysGit to MSYS2/MinGW-w64 we ran into this:

$ PATH=/mingw64/bin:"$PATH" gcc --version
gcc.exe (Rev1, Built by MSYS2 project) 4.9.1

$ cat test.c
#include 
static inline pid_t fork(void);
void main() {}

$ PATH=/mingw64/bin:"$PATH" gcc test.c
test.c:2:21: warning: conflicting types for built-in function 'fork'
 static inline pid_t fork(void);
 ^

Anyone got any ideas about this?

Best regards,

Ray.

--
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public