Discussion:
[9fans] cc nit?
(too old to reply)
erik quanstrom
2012-06-30 21:25:21 UTC
Permalink
i haven't tracked down thie issue yet, but it appears that ?c
generate unparsable acid output

; cat > void.c
typedef struct PNOTIFY PNOTIFY

struct PNOTIFY {
void emptiness;
};
<eot>; 8c -a void.c
void.c:1 not a function
void.c:5 syntax error, last name: emptiness
sizeofPNOTIFY = 0;
aggr PNOTIFY
{
T16
};

defn
PNOTIFY(addr) {
complex PNOTIFY addr;
T16
};
Bakul Shah
2012-06-30 21:33:44 UTC
Permalink
Post by erik quanstrom
i haven't tracked down thie issue yet, but it appears that ?c
generate unparsable acid output
; cat > void.c
typedef struct PNOTIFY PNOTIFY
struct PNOTIFY {
void emptiness;
}; ^^^^
Why would you do that?
erik quanstrom
2012-06-30 21:37:37 UTC
Permalink
Post by Bakul Shah
Post by erik quanstrom
i haven't tracked down thie issue yet, but it appears that ?c
generate unparsable acid output
; cat > void.c
typedef struct PNOTIFY PNOTIFY
struct PNOTIFY {
void emptiness;
}; ^^^^
Why would you do that?
because there's nothing that needs to be saved there for the k10
architecture.

- erik
Bakul Shah
2012-06-30 22:15:05 UTC
Permalink
Post by erik quanstrom
Post by Bakul Shah
Post by erik quanstrom
i haven't tracked down thie issue yet, but it appears that ?c
generate unparsable acid output
; cat > void.c
typedef struct PNOTIFY PNOTIFY
struct PNOTIFY {
void emptiness;
}; ^^^^
Why would you do that?
because there's nothing that needs to be saved there for the k10
architecture.
I think this void exension is just plain broken. Try

#include <u.h>
#include <libc.h>
void foo; void bar;
main() { print("%p, %p\n", &foo, &bar);

It fails in the link stage for me.

I would've tried

struct PNOTIFY {
char nothingness[0];
};

as it more directly expresses the intent (at least to me) but
that doesn't work either.
erik quanstrom
2012-07-01 13:47:59 UTC
Permalink
it's fixable with the following strategy
1. cc: for void's, don't emit anything from the compiler's acid generator
2. acid: accept empty aggrs.

i haven't pushed it to see if i can get acid to crash, and i don't have time
to right now, but this does improve the situation.

- erik

; diff -c /n/dump/2012/0701/sys/src/cmd/acid/dbg.y /sys/src/cmd/acid/dbg.y
/n/dump/2012/0701/sys/src/cmd/acid/dbg.y:75,82 - /sys/src/cmd/acid/dbg.y:75,85
zsemi :
| ';' zsemi

- members : member
- | members member
+ members :
+ {
+ $$ = nil;
+ }
+ | member members
{
$$ = an(OLIST, $1, $2);
}
; diff -c `{yesterday -n2 /sys/src/cmd/cc/acid.c} /sys/src/cmd/cc/acid.c
/n/dump/2012/0629/sys/src/cmd/cc/acid.c:112,117 - /sys/src/cmd/cc/acid.c:112,120
Bprint(&outbuf, " T%d\n", t->etype);
break;

+ case TVOID:
+ break; /* relies on acid being able to handle empty aggrs. */
+
case TIND:
if(s == S)
break;
erik quanstrom
2012-07-01 16:57:14 UTC
Permalink
Post by erik quanstrom
i haven't tracked down thie issue yet, but it appears that ?c
generate unparsable acid output
; cat > void.c
typedef struct PNOTIFY PNOTIFY
struct PNOTIFY {
void emptiness;
};
<eot>; 8c -a void.c
void.c:1 not a function
void.c:5 syntax error, last name: emptiness
...
I'm not sure where this is documented, but, isn't the problem (not just
syntactically) with the above the missing semicolon on the typedef line and
not the void'ness issue?
that's true, i did miss the semicolon. but that was a copypasta problem;
the issue still exists.

- erik
Comeau At9Fans
2012-07-01 16:54:17 UTC
Permalink
Post by erik quanstrom
i haven't tracked down thie issue yet, but it appears that ?c
generate unparsable acid output
; cat > void.c
typedef struct PNOTIFY PNOTIFY
struct PNOTIFY {
void emptiness;
};
<eot>; 8c -a void.c
void.c:1 not a function
void.c:5 syntax error, last name: emptiness
...
I'm not sure where this is documented, but, isn't the problem (not just
syntactically) with the above the missing semicolon on the typedef line and
not the void'ness issue?
--
Greg Comeau / 4.3.10.1 with C++0xisms now in beta!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Charles Forsyth
2012-07-01 20:39:11 UTC
Permalink
instead of trying to make void work as a data type declaration, it might be
clearer to accept an empty struct.
Comeau At9Fans
2012-07-01 22:22:17 UTC
Permalink
On Sun, Jul 1, 2012 at 4:39 PM, Charles Forsyth
Post by Charles Forsyth
instead of trying to make void work as a data type declaration, it might
be clearer to accept an empty struct.
Many compilers do just that, however, that said, unless the compiler is
prepared for it, since it effectively yields a struct of zero size which
normally is a no-go, it could produce bugs involving sizeof, initializers,
pointer addition et al, even some divisions by zero if the compiler is
making certain assumptions already, unless it already can have zero length
objects of this nature for some other reasons.
--
Greg Comeau / 4.3.10.1 with C++0xisms now in beta!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Charles Forsyth
2012-07-01 22:32:12 UTC
Permalink
Yes, I was assuming the same approach as for the existing void data
declaration, that the structure is given a nominal size,
for just the reasons you give. (That's what gcc seems to do.)
Post by Comeau At9Fans
Many compilers do just that, however, that said, unless the compiler is
prepared for it, since it effectively yields a struct of zero size which
normally is a no-go, it could produce bugs involving sizeof, initializers,
pointer addition et al, even some divisions by zero if the compiler is
making certain assumptions already, unless it already can have zero length
objects of this nature for some other reasons.
Charles Forsyth
2012-07-01 22:34:08 UTC
Permalink
Even better might be to do neither: eliminate support for void data, and
give the declaration a type that doesn't provoke so much discussion.
It's just a placeholder.
Post by Charles Forsyth
Yes, I was assuming the same approach as for the existing void data
declaration, that the structure is given a nominal size,
for just the reasons you give. (That's what gcc seems to do.)
Comeau At9Fans
2012-07-02 00:21:11 UTC
Permalink
On Sun, Jul 1, 2012 at 6:34 PM, Charles Forsyth
Post by Charles Forsyth
Even better might be to do neither: eliminate support for void data, and
give the declaration a type that doesn't provoke so much discussion.
It's just a placeholder.
Post by Charles Forsyth
Yes, I was assuming the same approach as for the existing void data
declaration, that the structure is given a nominal size,
for just the reasons you give. (That's what gcc seems to do.)
I don't know where this will lead for 8c et al, so I'll throw it out there
anyway in the spirit of placeholders:

int : 0;
--
Greg Comeau / 4.3.10.1 with C++0xisms now in beta!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Comeau At9Fans
2012-07-02 00:18:53 UTC
Permalink
On Sun, Jul 1, 2012 at 6:32 PM, Charles Forsyth
Post by Charles Forsyth
Yes, I was assuming the same approach as for the existing void data
declaration, that the structure is given a nominal size,
for just the reasons you give. (That's what gcc seems to do.)
Post by Comeau At9Fans
Many compilers do just that, however, that said, unless the compiler is
prepared for it, since it effectively yields a struct of zero size which
normally is a no-go, it could produce bugs involving sizeof, initializers,
pointer addition et al, even some divisions by zero if the compiler is
making certain assumptions already, unless it already can have zero length
objects of this nature for some other reasons.
Actually gcc gives it (the empty struct) sizeof zero (same as for its zero
length arrays). Comeau mimics that behavior in gcc-mode, but used to/still
can also generate a dummy internal member too (usually a char bringing
forth sizeof 1).
--
Greg Comeau / 4.3.10.1 with C++0xisms now in beta!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Charles Forsyth
2012-07-02 07:42:34 UTC
Permalink
You're right. I'd misread the assembly code.
Post by Comeau At9Fans
Actually gcc gives it (the empty struct) sizeof zero (same as for its zero
length arrays).
Charles Forsyth
2012-07-02 07:45:02 UTC
Permalink
Anyway, for a single use inside a single program, it's probably better just
to do what we'd do
if we couldn't just change the compiler, and change the type to a valid one
for data.

erik quanstrom
2012-07-01 22:45:22 UTC
Permalink
Post by Comeau At9Fans
Many compilers do just that, however, that said, unless the compiler is
prepared for it, since it effectively yields a struct of zero size which
normally is a no-go, it could produce bugs involving sizeof, initializers,
pointer addition et al, even some divisions by zero if the compiler is
making certain assumptions already, unless it already can have zero length
objects of this nature for some other reasons.
actually, kenc is pretty good about all these. if you have

struct fu {void x;};

and take sizeof(struct fu), that will give a diagnostic error.

the reason i avoided it was to not mess with the grammer, but if this is a
common thing, maybe it's no big deal.

though as charles points out, it is a bit of a waste of time.

- erik
Comeau At9Fans
2012-07-02 00:24:58 UTC
Permalink
Post by Comeau At9Fans
Post by Comeau At9Fans
Many compilers do just that, however, that said, unless the compiler is
prepared for it, since it effectively yields a struct of zero size which
normally is a no-go, it could produce bugs involving sizeof,
initializers,
Post by Comeau At9Fans
pointer addition et al, even some divisions by zero if the compiler is
making certain assumptions already, unless it already can have zero
length
Post by Comeau At9Fans
objects of this nature for some other reasons.
actually, kenc is pretty good about all these. if you have
struct fu {void x;};
and take sizeof(struct fu), that will give a diagnostic error.
the reason i avoided it was to not mess with the grammer, but if this is a
common thing, maybe it's no big deal.
though as charles points out, it is a bit of a waste of time.
If my memory serves, there is some wiggle room in C89 about how the empty
struct works, though generally it wouldn't fly, and C99 disallows it, while
C++ allows it (but it's sizeof > 0). Plus it's a common extension made
prevalent via gcc.
--
Greg Comeau / 4.3.10.1 with C++0xisms now in beta!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Loading...