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 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 refined.
[....]
> 
> The Extension (Basic)
> =====================
> 
> First, let's introduce a new syntax (note again, this is just an
> example. I don't suggest these particular symbols):
> 
>     float inverse(int x)
>     {
>         if (x == 0)
>             fail;
>         return 1.0f / x;
>     }
> 
>     ...
>     y = inverse(x) !! goto exit_inverse_failed;
> 


Syntax is not that important. To experiment your idea, 
I would suggest using a mixture of pragmas and builtins; 
you could perhaps have a new builtin_shahbaz_fail() and a pragma
#pragma SHAHBAZ  and then your temporary syntax would be

  float inverse(int x)
  {
      if (x == 0) builtin_shahbaz_fail();
      return 1.0f / x;
  }
  
  #pragma SHAHBAZ on_error_goto(exit_inverse_failed)
      { y = inverse(x); }
 
 
Then, you don't need to dig into GCC parser to add these builtin and pragma. 
You could add them with a GCC plugin (in C++) or using MELT http://gcc-melt.org/
 
Once you added a GCC pass to support your builtin and pragma 
(which is difficult, and means understanding the details of internals of GCC)
you could convince other people.
 
Notice that the GCC community is not friendly these days to new syntactic constructs.
 
BTW, once you have implemented a builtin and a pragma you could use preprocessor macros
to make these look more like your syntax.


I would believe that MELT is very well suited for such experiments.

Regards.
  
PS. Plugins cannot extend the C syntax (except thru attributes, builtins, pragmas).

-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***


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