public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* How to explain this syntax?
@ 2023-04-16 10:25 Andy
  2023-04-16 10:53 ` Andrew Haley
  2023-04-19 11:40 ` Andy
  0 siblings, 2 replies; 6+ messages in thread
From: Andy @ 2023-04-16 10:25 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 700 bytes --]

In gcc/gcc/testsuite/gcc.c-torture/compile/pr43635.c
we have

extern void d (void);

void (*foo (void)) (float)
{
  void (*(*x) (void)) (float) = d;
  return (*x) ();
}

d is a function without parameters and nothing returns.
foo is function without parameters and returns pointer to function with one
parameter float and also returning void?
what is type of x?
void (*(*x) (void)) (float) is on whole type definition of x or part is
type definition of x and part is cast d to x? which parts?
why not returns x but (*x) ()? don' t return pointer to function but call
this function?
I know, this is malignant example, in in real world can't be cast function
returning void to function returning value

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

* Re: How to explain this syntax?
  2023-04-16 10:25 How to explain this syntax? Andy
@ 2023-04-16 10:53 ` Andrew Haley
  2023-04-19 11:40 ` Andy
  1 sibling, 0 replies; 6+ messages in thread
From: Andrew Haley @ 2023-04-16 10:53 UTC (permalink / raw)
  To: gcc-help

On 4/16/23 11:25, Andy via Gcc-help wrote:
> void (*(*x) (void)) (float)

declare x as pointer to function (void) returning pointer to function (float) returning void

https://cdecl.org/

-- 
Andrew Haley  (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671


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

* Re: How to explain this syntax?
  2023-04-16 10:25 How to explain this syntax? Andy
  2023-04-16 10:53 ` Andrew Haley
@ 2023-04-19 11:40 ` Andy
  2023-04-19 11:53   ` Xi Ruoyao
  1 sibling, 1 reply; 6+ messages in thread
From: Andy @ 2023-04-19 11:40 UTC (permalink / raw)
  To: gcc-help

I meet odd struct + colon syntax:
in gcc/gcc/testsuite/gcc.c-torture/compile/init-3.c
is

struct something X = {
 foo: { },
 bar: 1,
};
bar:1 is one bit field? what means foo? is the same as
struct empty foo; where struct empty { };
colon is not only reserved to bitfields?

Second (init-2.c):
initializer

struct
{
  int e1, e2;
} v = { e2: 0 };
why not e2=0, colon instead of assign operator?

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

* Re: How to explain this syntax?
  2023-04-19 11:40 ` Andy
@ 2023-04-19 11:53   ` Xi Ruoyao
  2023-04-19 12:35     ` Andy
  0 siblings, 1 reply; 6+ messages in thread
From: Xi Ruoyao @ 2023-04-19 11:53 UTC (permalink / raw)
  To: Andy; +Cc: gcc-help

On Wed, 2023-04-19 at 13:40 +0200, Andy via Gcc-help wrote:
> I meet odd struct + colon syntax:
> in gcc/gcc/testsuite/gcc.c-torture/compile/init-3.c
> is
> 
> struct something X = {
>  foo: { },
>  bar: 1,
> };
> bar:1 is one bit field? what means foo? is the same as
> struct empty foo; where struct empty { };
> colon is not only reserved to bitfields?

It's an obsoleted GNU extension:

https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html

> 
> Second (init-2.c):
> initializer
> 
> struct
> {
>   int e1, e2;
> } v = { e2: 0 };
> why not e2=0, colon instead of assign operator?

The point of the test case is ensuring GCC backward compatible with the
old extension, though it's obsoleted.

The GCC test cases are test cases, not some "material to learn C".

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

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

* Re: How to explain this syntax?
  2023-04-19 11:53   ` Xi Ruoyao
@ 2023-04-19 12:35     ` Andy
  2023-04-19 12:41       ` Xi Ruoyao
  0 siblings, 1 reply; 6+ messages in thread
From: Andy @ 2023-04-19 12:35 UTC (permalink / raw)
  Cc: gcc-help

I don't learn C, but I am writing c90 Antlr grammar which should be as
compatible with GCC as possible.
I see many GNU extension, one is most significant is nested functions,
but all code is compilable with GCC with std=c90, not need std=gnu90,
although some code is compilable only with std=gnu90

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

* Re: How to explain this syntax?
  2023-04-19 12:35     ` Andy
@ 2023-04-19 12:41       ` Xi Ruoyao
  0 siblings, 0 replies; 6+ messages in thread
From: Xi Ruoyao @ 2023-04-19 12:41 UTC (permalink / raw)
  To: Andy; +Cc: gcc-help

On Wed, 2023-04-19 at 14:35 +0200, Andy via Gcc-help wrote:
> I don't learn C, but I am writing c90 Antlr grammar which should be as
> compatible with GCC as possible.
> I see many GNU extension, one is most significant is nested functions,
> but all code is compilable with GCC with std=c90, not need std=gnu90,
> although some code is compilable only with std=gnu90

-pedantic-errors will reject most GNU extensions if you don't want them.

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

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

end of thread, other threads:[~2023-04-19 12:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-16 10:25 How to explain this syntax? Andy
2023-04-16 10:53 ` Andrew Haley
2023-04-19 11:40 ` Andy
2023-04-19 11:53   ` Xi Ruoyao
2023-04-19 12:35     ` Andy
2023-04-19 12:41       ` Xi Ruoyao

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).