This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: GNU C extension: Function Error vs. Success
- From: Andrew Haley <aph at redhat dot com>
- To: Shahbaz Youssefi <shabbyx at gmail dot com>
- Cc: Julian Brown <julian at codesourcery dot com>, gcc at gcc dot gnu dot org
- Date: Mon, 10 Mar 2014 17:35:10 +0000
- Subject: Re: GNU C extension: Function Error vs. Success
- Authentication-results: sourceware.org; auth=none
- References: <CALeOzZ8kAOepbUsqRNWnGvHc=vAGC2M_NkHZ6+VZz3ybfs59HA at mail dot gmail dot com> <20140310145046 dot 2d5c4ca0 at octopus> <CALeOzZ8On5R7t+3_gQ+ec5Sqi4P1ysCTLUMd0ck5UK7nKiCs+A at mail dot gmail dot com> <531DF3D4 dot 9070403 at redhat dot com> <CALeOzZ_oDiKNU5SaB07ks0KHP6h=nW_9guwNobGwBAfOyL5z-Q at mail dot gmail dot com>
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)
> return (struct option_float){ .succeeded = false, .error_code = EDOM };
> return (struct option_float){ .value = 1.0f / x, .succeeded = true };
> }
>
Well, yes. This is rather wordy, but indeed it does the same thing.
> P.S. programming in a lot of languages is _mere syntax_ with respect
> to some others. Still, some syntaxes are good and some not. If we can
> improve GNU C's syntax to be shorter, but without loss of
> expressiveness or clarity, then why not!
Because C is a simple language. That's a feature: if you want more
language complexity, and C++ can already do what you want, what not
use C++? The usual argument is "I don't want all this other stuff."
Well, don't use it, then!
There seem to be many people who what what C++ can do, but say "I don't
want to use C++."
Andrew.