This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GNU C extension: Function Error vs. Success


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]