help on type compatibility?

C

Chris Torek

[given cp as a variable of type "const char *" and p as one
of type "char *"]

I some ways the more surprising example is that:

const char * const *pcp;
pcp = pp;

also requires a diagnostic. Surprising because this way round no
"const"ness is being lost.

Indeed, and this "works right" in C++. I do not know why the C99
folks did not adopt the C++ "const" rules here.
 
L

lawrence.jones

In comp.std.c Chris Torek said:
Indeed, and this "works right" in C++. I do not know why the C99
folks did not adopt the C++ "const" rules here.

Because the C++ folks chose to describe their language in a way that
isn't compatible with the way the C language was described, making it
necessary to translate the rules rather than just copying them, and
because C99 added the "restrict" qualifier that wasn't handled by the
rules.

-Larry Jones

Some people just don't have inquisitive minds. -- Calvin
 
W

WaterWalk

pete said:
I intended that last line to be test2("World")
but it doesn't make much difference.

This is the first time I hear about "function type". Even in K&R, I
don't remember any mention of this term. Thanks, pete. I'll look for
more about this.
 
D

David R Tribble

I don't follow that: neither pointer type is qualified, so item [2]
holds. Only the pointed-at types are differently qualified. The pointer
types themselves are both unqualified.

I agree.

Ark's code in question was:
typedef int test_t(char *s);
typedef int contest_t(const char *cs);
extern contest_t somefunction;
test_t *mypointer = somefunction; // A

[A] is an error, because it is attempting to remove the 'const'
from from a pointed-to parameter type.

On the other hand, this should work:
extern contest_t otherfunc;
contest_t myotherptr = otherfunc; // B

because is adding a 'const' qualifier to a pointed-to parameter
type, which IIRC is okay. In other words, parameter s is
assignment-compatible to parameter cs, so function pointer
otherfunc should be assignable to myotherfunc without needing
an explicit cast. (But I could be wrong.)

-drt
 
M

Micah Cowan

David R Tribble said:
I don't follow that: neither pointer type is qualified, so item [2]
holds. Only the pointed-at types are differently qualified. The pointer
types themselves are both unqualified.

I agree.

Ark's code in question was:
typedef int test_t(char *s);
typedef int contest_t(const char *cs);
extern contest_t somefunction;
test_t *mypointer = somefunction; // A

[A] is an error, because it is attempting to remove the 'const'
from from a pointed-to parameter type.

On the other hand, this should work:
extern contest_t otherfunc;

I'm assuming you meant:

extern test_t otherfunc;
contest_t myotherptr = otherfunc; // B

because is adding a 'const' qualifier to a pointed-to parameter
type, which IIRC is okay. In other words, parameter s is
assignment-compatible to parameter cs, so function pointer
otherfunc should be assignable to myotherfunc without needing
an explicit cast. (But I could be wrong.)


Yeah, unfortunately you're wrong.

For two types to be compatible, they must be identically
qualified. For /assignment/ purposes, a special exemption was made for
pointers to differently-qualified types, but those pointers
themselves--and indeed, the pointed-two types as well--are not
compatible.

-Micah
 
D

Dave Thompson

int (*) (char*) assigned int (*) (const char *)
Part of one of the clauses of 3.5.4.3 states: <snip>
(they're not compatible)

Right. And thus a diagnostic is required, and as for all required
diagnostics what if anything happens after that is up to the
implementation. And this doesn't change between C90/99.

Note however that T* and cv-T* are required to have the same
representation and alignment which according to a nonnormative
footnote is "intended" to allow interchangeability as arguments among
other cases. Although unlike signed-unsigned and char*-void* there is
not normative language for unprototyped and va_arg calls. Even so an
implementation would be quite perverse to break any of these.

- David.Thompson1 at worldnet.att.net
 
D

Douglas A. Gwyn

... if a footnote claims that something is true which cannot be derived from
the normative text, that claim is simply false, and can therefore be ignored.

No, footnotes cannot be ignored. Go back and pay more heed to
what I said upthread -- when it comes to understanding the scope
of certain requirements such as in the specific case being
discussed, what the total "truth" consists of might not be
apparent until *after* you take the footnote into account.
Note that the main text requirement uses a term that is not
fully and completely defined within the main text, but the
footnote tries to explain what is meant by the term. If you
ignore the footnote, then you cannot understand what is meant.
 
K

kuyper

I said that badly - it shouldn't be ignored - the discrepancy should be
fixed, either by changing the normative text, or by changing the
footnote; possibly both. However, the portions of the footnote that
can't be derived from the normative text can't be used to judge whether
or not an implementation conforms to the standard. That's what
"normative" means.
No, footnotes cannot be ignored. Go back and pay more heed to
what I said upthread -- when it comes to understanding the scope
of certain requirements such as in the specific case being
discussed, what the total "truth" consists of might not be
apparent until *after* you take the footnote into account.

It might not be apparant, but once you know that it was intended, it
must be possible to go back to the normative text and see that it does
indeed say what it didn't apparantly say.

I know that there are meta-standards; standards which specify how
standards are to be created, written, and interpreted. I am sure that
there's an ISO standard somewhere that defines precisely what
"normative" means in the context of an ISO standard. I don't have a
copy of that standard, so I'm not sure what it says about this. It's
quite possible that "normative" has a meaning in ISO standards that is
consistent with what you say. However, if so, it's another example of
specialized jargon with a meaning quite different from it's ordinary
English meaning, and I personally would have recommended that a
different word be used.

To say that a statement is "normative" means that it defines a norm
against which something is to be judged. In the context of the
standard, I'd expect that the thing which is being judged is
conformance with the standard. If non-normative text says that
something is true, that can't be derived from the normative text, then
conformance of a particular implementation to the standard can't be
judged by whether or not that statement is true about that particular
implementation.

As the standard itself informs us (in a non-normative section), the
non-normative text is for information only. Using it for such
judgements would be using it for something more than information. When
it contains anything other than information, when it establishes
requirements not deriveable from normative text, then it is false
information, and should be treated as such.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top