Re: GNU C extension: Function Error vs. Success

2014-03-11 Thread Shahbaz Youssefi
On Tue, Mar 11, 2014 at 1:26 PM, David Brown wrote: > On 10/03/14 18:26, Shahbaz Youssefi wrote: > You can tell the compiler about the likely paths: > > struct option_float inverse(int x) { > if (__builtin_expect(x != 0, 1)) { > return (struct option_float){ .value = 1.0f

Re: GNU C extension: Function Error vs. Success

2014-03-11 Thread David Brown
On 10/03/14 18:26, Shahbaz Youssefi wrote: > I'm mostly interested in C. Nevertheless, you can of course also do > the same in C: > > struct option_float > { > float value; > int error_code; > bool succeeded; > }; > > struct option_float inverse(int x) { > if (x == 0) > return (

Re: GNU C extension: Function Error vs. Success

2014-03-10 Thread Andrew Haley
On 03/10/2014 05:26 PM, Shahbaz Youssefi wrote: > I'm mostly interested in C. Nevertheless, you can of course also do > the same in C: > > struct option_float > { > float value; > int error_code; > bool succeeded; > }; > > struct option_float inverse(int x) { > if (x == 0) > ret

Re: GNU C extension: Function Error vs. Success

2014-03-10 Thread Shahbaz Youssefi
I'm mostly interested in C. Nevertheless, you can of course also do the same in C: struct option_float { float value; int error_code; bool succeeded; }; struct option_float inverse(int x) { if (x == 0) return (struct option_float){ .succeeded = false, .error_code = EDOM }; ret

Re: GNU C extension: Function Error vs. Success

2014-03-10 Thread Andrew Haley
On 03/10/2014 03:09 PM, Shahbaz Youssefi wrote: > Regarding C++ exceptions: exceptions are not really nice. They can > just make your function return without you even knowing it (forgetting > a `try/catch` or not knowing it may be needed, which is C++'s fault > and probably could have been done bet

Re: GNU C extension: Function Error vs. Success

2014-03-10 Thread Shahbaz Youssefi
Thanks for the hint. I would try to learn how to do that and experiment on the idea if/when I get the time. I could imagine why the community isn't interested in new syntax in general. Still, you may never know if an idea would be attractive enough to generate some attention! :) On Mon, Mar 10, 20

Re: GNU C extension: Function Error vs. Success

2014-03-10 Thread Igor Pashev
10.03.2014 18:27, Shahbaz Youssefi пишет: FILE *fin = fopen("filename", "r") !! goto exit_no_file; Or maybe permission denied? ;-)

Re: GNU C extension: Function Error vs. Success

2014-03-10 Thread Basile Starynkevitch
On Mon, Mar 10, 2014 at 03:27:06PM +0100, Shahbaz Youssefi wrote: > Hi, > > First, let me say that I'm not subscribed to the mailing list, so > please CC myself when responding. > > This post is to discuss a possible extension to the GNU C language. > Note that this is still an idea and not refin

Re: GNU C extension: Function Error vs. Success

2014-03-10 Thread Shahbaz Youssefi
Hi Julian, Thanks for the feedback. Regarding C++ exceptions: exceptions are not really nice. They can just make your function return without you even knowing it (forgetting a `try/catch` or not knowing it may be needed, which is C++'s fault and probably could have been done better). Also, they r

Re: GNU C extension: Function Error vs. Success

2014-03-10 Thread Julian Brown
On Mon, 10 Mar 2014 15:27:06 +0100 Shahbaz Youssefi wrote: > Feedback > > > Please let me know what you think. In particular, what would be the > limitations of such a syntax? Would you be interested in seeing this > extension to the GNU C language? What alternative symbols do you think

GNU C extension: Function Error vs. Success

2014-03-10 Thread Shahbaz Youssefi
Hi, First, let me say that I'm not subscribed to the mailing list, so please CC myself when responding. This post is to discuss a possible extension to the GNU C language. Note that this is still an idea and not refined. Background == In C, the following code structure is ubiquitous: