Discussion:
[9fans] c compiler bug
(too old to reply)
erik quanstrom
2013-02-17 02:38:09 UTC
Permalink
i don't think this should link, since wrongaddr calls
fn with an Outer* not an Inner*.

#include <u.h>
#include <libc.h>

typedef struct Inner Inner;
typedef struct Outer Outer;

struct Inner {
int x;
};

struct Outer {
char buf[0x1000];
Inner;
};

void
wrongaddr(Outer *o)
{
static void fn(Outer*);

fn(o);
}

void
main(void)
{
Outer *o;

o = malloc(sizeof *o);
memset(o, 0, sizeof *o);
print("addr o %#p\n", o);
print("addr o.x %#p\n", &o->x);
wrongaddr(o);
}

static void
fn(Inner *i)
{
print("fn addr i.x %#p\n", &i->x);
}
; 6.cbug
addr o 0x4018f0
addr o.x 0x4028f0
fn addr i.x 0x4018f0
Comeau At9Fans
2013-02-18 13:02:28 UTC
Permalink
Post by erik quanstrom
i don't think this should link, since wrongaddr calls
fn with an Outer* not an Inner*.
...
Normally in more mainstream C the nested "static void fn(Outer*);"
declaration would produce a diagnostic and instead what it (the compiler
and the code) seems to be doing is setting up allowing the call to compile
and once that is satisfied then the subsequent definition "has" to match
it, as perhaps a way to do type punning.
--
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
2013-02-18 14:38:03 UTC
Permalink
seems to be doing is setting up allowing the call to compile and once that
is satisfied then the subsequent definition "has" to match it, as perhaps a
way to do type punning.
No, the compiler is simply applying scope rules. Without that inner
declaration explicitly overriding the outer declaration--whether static or
extern is used--
it will not compile (eg, if you put "static void fn(Outer*);" or "extern
void fn(Outer*);" and remove static from fn in the file scope).

The behaviour is undefined in ANSI C if two declarations that refer to the
same object or function do not have compatible types
(normally, you're protected by another rule that you can't have
incompatible declarations *in the same scope*).

ANSI C does, however, forbid the inner static declaration (which surprised
me)
"The declaration of an identifier for a function that has block scope shall
have no explicit storage-class specifier other than extern." (6.7.1)
Charles Forsyth
2013-02-18 15:10:47 UTC
Permalink
since nested functions are not allowed, applying nested scope seems
a bit odd.
Nevertheless, that is what it is.
erik quanstrom
2013-02-18 15:02:12 UTC
Permalink
No, the compiler is simply applying scope rules. Without that inner
declaration explicitly overriding the outer declaration--whether
static or extern is used-- it will not compile (eg, if you put "static
void fn(Outer*);" or "extern void fn(Outer*);" and remove static from
fn in the file scope).
since nested functions are not allowed, applying nested scope seems
a bit odd. anyway, ...

if the declaration were in the same place but the referenced
function were in another file, the -T would have prevented the
link. my question is, why doesn't the c compiler internally
apply the same rule?

- erik
Comeau At9Fans
2013-02-21 17:17:36 UTC
Permalink
No, the compiler is simply applying scope rules. Without that inner
declaration explicitly overriding the outer declaration--whether
static or extern is used-- it will not compile (eg, if you put "static
void fn(Outer*);" or "extern void fn(Outer*);" and remove static from
fn in the file scope).
since nested functions are not allowed, applying nested scope seems
a bit odd. anyway, ...
It's often to be refrained from even if it were extern and not static.
if the declaration were in the same place but the referenced
function were in another file, the -T would have prevented the
link. my question is, why doesn't the c compiler internally
apply the same rule?
Wild guessing that it's probably an oversight that it got allowed.
--
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
2013-02-21 17:13:03 UTC
Permalink
On Mon, Feb 18, 2013 at 9:38 AM, Charles Forsyth
Post by Charles Forsyth
seems to be doing is setting up allowing the call to compile and once
that is satisfied then the subsequent definition "has" to match it, as
perhaps a way to do type punning.
No, the compiler is simply applying scope rules. Without that inner
declaration explicitly overriding the outer declaration--whether static or
extern is used--
it will not compile (eg, if you put "static void fn(Outer*);" or "extern
void fn(Outer*);" and remove static from fn in the file scope).
The behaviour is undefined in ANSI C if two declarations that refer to the
same object or function do not have compatible types
(normally, you're protected by another rule that you can't have
incompatible declarations *in the same scope*).
ANSI C does, however, forbid the inner static declaration (which surprised
me)
"The declaration of an identifier for a function that has block scope
shall have no explicit storage-class specifier other than extern." (6.7.1)
We're probably saying the same thing. As you say ANSI C forbids it hence
my comment about normally a diagnostic from a so-called mainstream
compiler. And as you say without a declaration it would not compile
either. The declaration should normally be in global scope (it could have
been), which would have also produced a diagnostic since Inner/Outer don't
match. That leaves the declaration where Eric showed it, which the Plan 9
compiler obviously allowed. As you note the net effect is it's undefined
(if we're using ANSI C as the metric) hence created a kind of type pun
(even if the original code did it as a mistake).
--
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?
hiro
2013-02-21 18:13:01 UTC
Permalink
can you please stop sending html mails? thanks
Post by Comeau At9Fans
On Mon, Feb 18, 2013 at 9:38 AM, Charles Forsyth
Post by Charles Forsyth
seems to be doing is setting up allowing the call to compile and once
that is satisfied then the subsequent definition "has" to match it, as
perhaps a way to do type punning.
No, the compiler is simply applying scope rules. Without that inner
declaration explicitly overriding the outer declaration--whether static or
extern is used--
it will not compile (eg, if you put "static void fn(Outer*);" or "extern
void fn(Outer*);" and remove static from fn in the file scope).
The behaviour is undefined in ANSI C if two declarations that refer to the
same object or function do not have compatible types
(normally, you're protected by another rule that you can't have
incompatible declarations *in the same scope*).
ANSI C does, however, forbid the inner static declaration (which surprised
me)
"The declaration of an identifier for a function that has block scope
shall have no explicit storage-class specifier other than extern." (6.7.1)
We're probably saying the same thing. As you say ANSI C forbids it hence
my comment about normally a diagnostic from a so-called mainstream
compiler. And as you say without a declaration it would not compile
either. The declaration should normally be in global scope (it could have
been), which would have also produced a diagnostic since Inner/Outer don't
match. That leaves the declaration where Eric showed it, which the Plan 9
compiler obviously allowed. As you note the net effect is it's undefined
(if we're using ANSI C as the metric) hence created a kind of type pun
(even if the original code did it as a mistake).
--
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?
John Floren
2013-02-21 18:22:08 UTC
Permalink
I think his mail client is just too world-class, breathtaking,
amazing, and fabulous--have you tried it?
Post by hiro
can you please stop sending html mails? thanks
Post by Comeau At9Fans
On Mon, Feb 18, 2013 at 9:38 AM, Charles Forsyth
Post by Charles Forsyth
seems to be doing is setting up allowing the call to compile and once
that is satisfied then the subsequent definition "has" to match it, as
perhaps a way to do type punning.
No, the compiler is simply applying scope rules. Without that inner
declaration explicitly overriding the outer declaration--whether static or
extern is used--
it will not compile (eg, if you put "static void fn(Outer*);" or "extern
void fn(Outer*);" and remove static from fn in the file scope).
The behaviour is undefined in ANSI C if two declarations that refer to the
same object or function do not have compatible types
(normally, you're protected by another rule that you can't have
incompatible declarations *in the same scope*).
ANSI C does, however, forbid the inner static declaration (which surprised
me)
"The declaration of an identifier for a function that has block scope
shall have no explicit storage-class specifier other than extern." (6.7.1)
We're probably saying the same thing. As you say ANSI C forbids it hence
my comment about normally a diagnostic from a so-called mainstream
compiler. And as you say without a declaration it would not compile
either. The declaration should normally be in global scope (it could have
been), which would have also produced a diagnostic since Inner/Outer don't
match. That leaves the declaration where Eric showed it, which the Plan 9
compiler obviously allowed. As you note the net effect is it's undefined
(if we're using ANSI C as the metric) hence created a kind of type pun
(even if the original code did it as a mistake).
--
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?
erik quanstrom
2013-02-21 18:39:14 UTC
Permalink
Post by John Floren
I think his mail client is just too world-class, breathtaking,
amazing, and fabulous--have you tried it?
Post by hiro
can you please stop sending html mails? thanks
why does this bother anybody? i hadn't even noticed, and i
use nedmail to read my mail. which is somewhat of an
admission of failure. i used to just bring up my mail box in
acme until google started base64ing heavily. which is oddly
another admission of defeat. after 40 years of trying, we still don't
have 8-bit clean email.

- erik
Comeau At9Fans
2013-02-21 18:46:32 UTC
Permalink
Post by erik quanstrom
Post by John Floren
I think his mail client is just too world-class, breathtaking,
amazing, and fabulous--have you tried it?
Post by hiro
can you please stop sending html mails? thanks
why does this bother anybody? i hadn't even noticed, and i
use nedmail to read my mail. which is somewhat of an
admission of failure. i used to just bring up my mail box in
acme until google started base64ing heavily. which is oddly
another admission of defeat. after 40 years of trying, we still don't
have 8-bit clean email.
It's "just" gmail, perhaps my own admission of failure? :)
--
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?
John Floren
2013-02-21 18:51:53 UTC
Permalink
On Thu, Feb 21, 2013 at 10:46 AM, Comeau At9Fans
Post by Comeau At9Fans
Post by erik quanstrom
Post by John Floren
I think his mail client is just too world-class, breathtaking,
amazing, and fabulous--have you tried it?
Post by hiro
can you please stop sending html mails? thanks
why does this bother anybody? i hadn't even noticed, and i
use nedmail to read my mail. which is somewhat of an
admission of failure. i used to just bring up my mail box in
acme until google started base64ing heavily. which is oddly
another admission of defeat. after 40 years of trying, we still don't
have 8-bit clean email.
It's "just" gmail, perhaps my own admission of failure? :)
Gmail has interesting ideas sometimes about when it should send HTML.
I seem to have figured out how to make it always send plain-text, but
unfortunately I can't remember how exactly I did that.


john
hiro
2013-02-21 19:36:51 UTC
Permalink
Sorry, google's inconsistent mail interface made me post to the list
instead of private. I didn't mean to make this a discussion of
google's web technolgy, I just want to promote the sending of certain
compatible formats that everyone can read without problems.

My gmail only sends

Content-Type: text/plain; charset=UTF-8

Your's can, too.
andrey mirtchovski
2013-02-21 19:58:04 UTC
Permalink
good day. is this the p9p on osx help forum?
Matthew Veety
2013-02-21 20:24:24 UTC
Permalink
No.
Post by andrey mirtchovski
good day. is this the p9p on osx help forum?
David Leimbach
2013-02-21 20:27:58 UTC
Permalink
Can I run it on my iPhone?

Sent from my iPhone
Post by andrey mirtchovski
good day. is this the p9p on osx help forum?
steve
2013-02-21 20:36:48 UTC
Permalink
no, but drawterm will (i believe).
Post by David Leimbach
Can I run it on my iPhone?
Sent from my iPhone
Post by andrey mirtchovski
good day. is this the p9p on osx help forum?
Kurt H Maier
2013-02-21 18:51:17 UTC
Permalink
Post by erik quanstrom
Post by John Floren
I think his mail client is just too world-class, breathtaking,
amazing, and fabulous--have you tried it?
Post by hiro
can you please stop sending html mails? thanks
why does this bother anybody? i hadn't even noticed, and i
use nedmail to read my mail. which is somewhat of an
admission of failure. i used to just bring up my mail box in
acme until google started base64ing heavily. which is oddly
another admission of defeat. after 40 years of trying, we still don't
have 8-bit clean email.
- erik
Are you seriously marking this request WORKSFORME
Continue reading on narkive:
Loading...