This is the mail archive of the
mailing list for the GCC project.
Re: GNU C extension: Function Error vs. Success
- From: Julian Brown <julian at codesourcery dot com>
- To: Shahbaz Youssefi <shabbyx at gmail dot com>
- Cc: <gcc at gcc dot gnu dot org>
- Date: Mon, 10 Mar 2014 14:50:46 +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>
On Mon, 10 Mar 2014 15:27:06 +0100
Shahbaz Youssefi <email@example.com> wrote:
> 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
> would better show the intention/simplify parsing/look more beautiful?
I suggest you think about how this is better than C++ exceptions, and
also consider alternatives like OCaml's option types that can be used
to achieve similar ends.
For your suggested syntax at function call sites, consider that
functions can be called in more complicated ways than simply as "bar =
foo();" statements, and the part following the "!!" in your examples
appears to be a statement itself: in more complicated expressions, that
interleaving of expressions and statements going to get very ugly very
x = foo() + bar();
would need to become something like:
x = (foo() !! goto label1) + (bar () !! goto label2);
And there are all sorts of issues with that.
Anyway, I quite like the idea of rationalising error-code returns in C
code, but I don't think this is the right way of going about it.