public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* C language extension - Automatically cast
@ 2021-05-02 12:14 Sławomir Lach
  2021-05-28 16:22 ` Florian Weimer
  0 siblings, 1 reply; 2+ messages in thread
From: Sławomir Lach @ 2021-05-02 12:14 UTC (permalink / raw)
  To: gcc

In desperation made by programming in GTK+ I realized, some of object 
languages could been implemented in C, but only these not require to made 
changes in programs in runtime (compiler output).

One of items is automatically cast. For example I declared variable called 
Button of GtkButton and pass it to function requires GtkWidget. Why do not 
automatically cast to GtkWidget (like in class hierarchy or conversion 
operator in C++ or some extra constructors)? But .. it's rather conversion 
operator.

It could looks like:
__gcc_parent_type GtkWidget __gcc_parent_type_for GtkButton, GtkLabel, 
GtkTextView
__gcc_parent_type GtkBin __gcc_parent_type_for GtkWindow, GtkBox

What do you think?

It makes sense, because in this case there's no way to made mistake by 
avoiding extra conversion. Function expected any of GtkWidget (for example), 
so passing GtkButton is good. Code would be cleaner, hands will be in better 
shape and we save programmers time.



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: C language extension - Automatically cast
  2021-05-02 12:14 C language extension - Automatically cast Sławomir Lach
@ 2021-05-28 16:22 ` Florian Weimer
  0 siblings, 0 replies; 2+ messages in thread
From: Florian Weimer @ 2021-05-28 16:22 UTC (permalink / raw)
  To: Sławomir Lach; +Cc: gcc

* Sławomir Lach:

> One of items is automatically cast. For example I declared variable called 
> Button of GtkButton and pass it to function requires GtkWidget. Why do not 
> automatically cast to GtkWidget (like in class hierarchy or conversion 
> operator in C++ or some extra constructors)? But .. it's rather conversion 
> operator.
>
> It could looks like:
> __gcc_parent_type GtkWidget __gcc_parent_type_for GtkButton, GtkLabel, 
> GtkTextView
> __gcc_parent_type GtkBin __gcc_parent_type_for GtkWindow, GtkBox
>
> What do you think?

-fplan9-extensions already implements support for something like this.

But for portable code in that style, you should probably use C++
instead.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-28 16:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-02 12:14 C language extension - Automatically cast Sławomir Lach
2021-05-28 16:22 ` Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).