Reading from files and range of char and friends

J

James Kuyper

On Tue, 22 Mar 2011 15:19:27 -0700


Usual meaning minus the implication of transitivity.

What I consider to be the usual meaning of "same" is rendered almost
completely non-existent by removing transitivity. Whatever it is that
you think is left of the idea after removing that feature needs to be
explained in considerably more detail than the above paragraph.

More to the point, the key flaw in the footnote is neither the symmetry
nor the transitivity of SRAR(); it's the failure to keep in mind that
there are features of a type other than it's representation and
alignment which can affect the interchangeability with another type.
I have no reason to do that. I did say above that my default assumption
is that common English words are used with their common meaning. But in
the case of "same" as it appears in footnote 39 this assumption leads
to problems.

No, it is the phrase "is meant to imply" that leads to the problems;
"same" is just an innocent bystander. Larry Jones has posted a message
in another branch of this thread that describes the intended meaning.
Keith has suggested that more appropriate wording to cover the intended
meaning would have used the phrase "recommended practice"; I agree.
There's no need to assume that "same" was intended to convey a meaning
almost completely divorced from it's normal one.

....
Of course it could. But the relevant question is would it be guaranteed
to be true without assuming that SRAR() is symmetric and transitive ?

I can't even imagine what "same" would mean if it were neither symmetric
nor transitive. Without those two features, I would strongly recommend
using some entirely different English word for whatever concept it is
that you're trying to describe - perhaps "similar"? Though it does have
symmetry, it lacks transitivity, which would probably be sufficient.
However, a requirement that two type have "similar representation and
alignment" would be so vague as to be completely useless, and almost
completely untestable - but I think that fault is inherent in any
alternative definition for "same" which abandons either transitivity or
symmetry.

Could you explain the concept in more detail?
 
L

lawrence.jones

Keith Thompson said:
I suggest that the wording of the footnote does not effective convey
that intent. In particular, I've always read the phrase "meant to
imply" to refer to a logical implication, not a recommendation.

In that case, it would simply have said "implies" rather than "is meant
to imply".
Several sections of the standard have "Recommended practice"
subsections; the term is even defined in 3.16:

I'm almost positive the footnote predates those sections.
There are two footnotes that use the phrase "meant to imply", both in
section 6.2.5. I suggest that replacing both with a "Recommend
practice" subsection would be a substantial improvement.

The committee just added a couple more in London. I'll certainly
consider your suggestion.
Can you expand on that a bit? What "force" can a footnote have
without imposing a requirement?

It can explain or disambiguate a requirement that is made in normative
text (the requirement might be incomprehensible without the footnote).
It can also make recommendations, as in this case.
Oh, and speaking of footnotes, it would have been useful for N1256
to retain the same numbering of foonotes seen in the original C99
standard. Newly added foonotes might be labeled "42a", "42b", and
so forth. I think some Ada standard drafts have taken this approach.
(Section and paragraph numbers have *mostly* remained the same,
but those have also changed in a few cases.)

Yes, it would, but it's excruciatingly hard to do without making the
document unmaintainable.
 
K

Keith Thompson

In that case, it would simply have said "implies" rather than "is meant
to imply".

Ok, I'll certainly take your word for it that that was the intent.
But even knowing what was behind it, I'm still having trouble
reading it that way. The "is meant to" *seems* (to me) to mean
"this was what we had in mind", and "imply" still denotes, to me,
a logical implication.

I suppose I'm beating a dead horse here.
I'm almost positive the footnote predates those sections.


The committee just added a couple more in London. I'll certainly
consider your suggestion.

Cool, thanks.
It can explain or disambiguate a requirement that is made in normative
text (the requirement might be incomprehensible without the footnote).

The ideal solution, of course, is to make the requirement itself
comprehensible. I suppose that's not always practical.
It can also make recommendations, as in this case.


Yes, it would, but it's excruciatingly hard to do without making the
document unmaintainable.

Is the pdf created with a tool that numbers the footnotes automatically?
(I see that both the C99 standard and n1256.pdf were created by "Acrobat
Distiller Command 3.0 for HP-UX A.09.01 and later (HPPA)"; I've never
used it myself.)

Speaking of the pdf, how difficult would it be to have index entries
link to the referenced text?
 
S

Spiros Bousbouras

Quote B {}

Quote A {
}

It seemed perfectly obvious to me what interchangeability means, but if
you can actually believe that the above sentence makes any sense
whatsoever, we must differ in our understanding of that term at a very
fundamental level. To figure out where our understandings differ, I'm
going to have to explain my own understanding in tedious detail; feel
free to explain your own understanding of the term in similar detail, or
simply identify the differences.

For types T1 and T2 I define INPL(T1 , T2) ("IN PLace") to mean
that by using the standard and without considering the peculiarities of
any specific implementation you can reach the following conclusion :
for every i>0, for every function foo() which takes at least i
arguments , for every call foo() which has an object of type T2 given
by expression E at position i and the call does not cause undefined
behavior , then by putting at position i "(T1)E" and keeping everything
else the same , the function will operate in precisely the same manner
i.e. return the same value (if it returns a value) , cause the same
side effects etc.

I call T1 and T2 interchangeable (as arguments to functions) if we have
INPL(T1 , T2) and INPL(T2 , T1) .

So for example char* and void* are interchangeable.

In quote A I pointed out that if you have at some point in the code
foo(...,E,...) and futher down foo(...,(T1)E,...) then it may happen
that the object in position i may be passed in register R in the first
call and R' in the second call with R!=R' and the types being
interchangeable or compatible has nothing to do with it. From your
puzzled reaction I take it that when you spoke of "different registers"
you had something else in mind. But despite your long post I still
don't know what nor am I sure what you mean by interchangeable. Before
reading the post I'm replying to I was assuming that you had in mind
more or less the same definition I give above , possibly with less
detail , but now I'm not sure. But never mind. With enough perseverance
we'll manage to understand each other even if it means beaming down on
a planet and fighting a monster.

[...]
Whenever a pair of SRAR types is not compatible and have no implicit
conversions between them, using one in place of the other is generally
at least a constraint violation, and otherwise has undefined behavior (I
didn't notice any cases where it has implementation-defined behavior,
but I may have missed a case).

If it's a constraint violation, the implementation is required to
diagnose the program, and is not required to translate or execute it.
Therefore, it seems to me that interchangeability, if it were indeed
implied by SRAR, would be meaningful only in those cases which have
undefined behavior.

And here you lost me. Interchangeability being meaningful has nothing
to do with whether it is implied by SRAR or anything else. If A has a
meaningful definition then A is meaningful. You can't know whether B
implies A without first knowing that A is meaningful. Similarly I can't
imagine what connection can there possibly be between interchangeability
being meaningful and undefined behavior or lack thereof.
It can only mean that, despite the fact that the
behavior is undefined by the standard, the forms of behavior that are
actually possible are constrained by the fact that they are SRAR types,
to produce the expected results.

If the behavior is undefined then there are no constraints whatsoever
nor are there any expected results. Undefined behavior can turn your
computer into a frog for all you know.
By "expected results", I mean the following: for pointers, the pointer
value received will point at the same location in memory, though with a
different type. For _Complex, the corresponding array of double will
contain the real and imaginary components of the complex number. For
_Imaginary, the corresponding real value will be the same as the
imaginary component of the the _Imaginary one. For the cases which
differ in cv-qualification, the values will be the same as if by
implicit conversion.

For interchangeability as function arguments:
6.5.2.2p6:
a) A function is called with a K&R style declaration in scope. The
promoted type of an argument passed to the function is not compatible
with the type of the corresponding parameter in the function's
definition, but they are SRAR types.
b) A function is called with a prototype that ends with an ellipsis,
follows those same rules with respect to parameters after the last
declared parameter.
Note that this clause contains an exception that says, in effect, that
void* and pointers to character types are interchangeable - but only in
these contexts.

6.5.2.2p9: A function is called with a prototype in scope that specifies
a type for a parameter that is incompatible with the type declared for
that parameter in the function definition, but they are SRAR types.

In each of these cases, if the ABI used by the implementation calls for
the two SRAR types to be placed in different registers, then the calling
function will place the argument's value in one register, but the
calling function

I take it that last line should read "called function".
will try to retrieve it from a different register. Such
an ABI would impose severe complications on <stdarg.h> if it applied to
functions with a variable number of arguments, but for calls to other
types of functions it's not particularly odd or hard to implement (it
would be hard to motivate such an ABI feature, but that's not relevant
to my argument).
With such an ABI, the attempt to interchange the types has failed,
because the information was not successfully passed from the calling
function to the called function.

All this may happen but I still don't see how it justifies your quote
B. Perhaps this particular ABI makes it impossible to write a
conforming C implementation ? And I'm still not clear what scenario
you have in mind. Could you show some C code which may cause all these
things to happen ?
For interchangeability as return types from functions:
6.5.2.2p9: a function is called with a prototype in scope that specifies
a return type that is incompatible with the return type specified in the
function definition, but they are SRAR types.

In this case, if the ABI used by the implementation specifies that the
two SRAR types must be placed in different registers, then the called
function will place it's return value in one register, while the calling
function will attempt to read that value from a different register.
Attempting to interchange the types has failed again, because the
information was not successfully passed from the called function to the
calling function.

For interchangeability of SRAR types as members of unions, I cannot come
up with a good counter-example. This might be because the standard is
right in this case, but it's more likely due to a lack of imagination on
my part.

That's ok , for the time being I'm more concerned with understanding
what you mean than covering all cases. If you feel you can illustrate
your point by restricting your attention to arguments to functions
that's fine by me.
The rule is that if an alternative definition, provided neither by the
standard itself, nor by ISO/IEC 2382−1 or ISO 31−11, the the meaning
from ordinary English (as used in IT contexts) applies. I don't have
copies of either ISO/IEC 2382−1 or ISO 31−11, so I can't be sure, but I
doubt that either one of them provides a definition of the word "same"
that is sufficiently unconventional as to invalidate SRAR transitivity.

I doubt it too.
In both cases, the standard explicitly provides the alternative
definition that applies when those terms are used in the context of the
standard. The standard provides no alternative definition for "same",
and gives us no reason to suspect that any meaning other than the
conventional English meaning is intended.

I commented on that in [1].
Yes, but that's not the contradiction you were describing. You were
describing a non-existent contradiction between SRAR(unsigned char*,
char*) and the fact that they are incompatible types. That incorrect
belief was an essential step in reaching the faulty conclusion that
there was a contradiction between those two facts.

It's not clear to me what distinction you're making here. If the
correctness of the belief has to be used in reaching a contradiction
then there's no contradiction "between those two facts" , the
contradiction arises if we assume that a) "Same" in footnote 39 of
6.2.5 p27 has its usual meaning b) The belief expressed in footnote 39
is correct c) unsigned char* and char* are not compatible d) A few
other parts of the standard. That's the contradiction I was describing
in [2] where I used the term "contradiction" and I suggested that we
resolve the contradiction by abandoning the assumption that "SRAR is
transitive" which follows from a).
That's not a special rule for a special kind of logic. It's a fact
derivable from the ordinary rules of conventional logic.

What do you mean by "conventional logic" ? If you mean the logic we use
in everyday life then for the most part it doesn't have formal rules.
On occasion you may hear someone refer to some formal rule but I don't
think that most people would agree that "if the moon is made out of
cheese then 1 equals 2" is a correct implication although it is correct
in some formal logics and in classical logic in particular.
Reaching a conclusion of "not-A" from an argument whose premises include
"A", is a little too informal for my tastes.

That might have been perfectly legitimate depending on what the other
premises were. But in any case I don't recall doing any such thing.
Can you provide a quote ?
Your tastes may differ, in
which case we have nothing useful to discuss.


I think the derived fact (NOT an assumption)

Ok , the assumption that "same" is used with its usual meaning in
footnote 39.
that SRAR is transitive is
precisely as useful as SRAR itself. In a theoretical sense, both are
pretty much useless, without the corresponding guarantee of
interchangeability. In a practical sense, interchangeability of SRAR
types is a reality on most real systems, making SRAR moderately useful,
and the transitivity of SRAR comparably useful.

Could you show me some code which you find useful and depends on the
transitivity of SRAR ?
No, not really. I would expect that anyone writing such code would
intend to produce precisely the behavior that would be produced by
reason of the newly-guaranteed interchangeability of char* and unsigned
char*. If so, the author would be annoyed, rather than pleased, to
receive such warnings.

How can you be sure he didn't make a mistake ? Apart from that , does
your idea of interchangeability imply that the assignment from unsigned
char to char , which may happen when strcmp is executing , will always
produce predictable results ?
Keep in mind that footnotes are non-normative, so placing such a clause
in a footnote would be pointless.

It would stop the footnote from being misleading so it wouldn't be
pointless at all.
Footnotes are supposed to point out
in-obvious facts that can be derived from the facts given in normative
text; footnotes cannot be the source of new facts about C.
Interchangeability was supposedly derivable from "same representation
and alignment"; my objection is not to the interchangeability, but to
the fact that is not in fact derivable from those things.

And the addition I'm suggesting would alert the unwary reader to the
fact that the footnote is not the full story with regards to
interchangeability.



[1] <[email protected]>
http://groups.google.com/group/comp.lang.c/msg/d444fb5c8d154e4e?dmode=source

[2] <[email protected]>
http://groups.google.com/group/comp.lang.c/msg/1b34271463a527f6?dmode=source
 
S

Spiros Bousbouras

There are seven cases where the standard currently requires "same
representation and alignment" (and incorrectly suggests in non-normative
footnotes that this implies interchangeability as arguments to
functions, return values from functions, and members of unions):

The footnotes don't imply that interchangeability is required, they say
that it is intended to work.[/QUOTE]

Could you show some code which is intended to work ?
This is guidance to implementors: If you
can possibly make it work, you should. If you can't, you still conform,
but users are going to be disappointed.

[...]
 
S

Spiros Bousbouras

Spiros Bousbouras said:
On Tue, 22 Mar 2011 15:19:27 -0700
It's best to refer to footnotes by the section and paragraph to which
they apply. Footnote 39 happens to be the same in the original C
standard and N1256, but later foonotes differ. It applies to 6.2.5p26.

The post appearing in [1] has full references. More relevant to the
discussion is the fact that footnote 39 is referenced in 6.2.5 p27.

Yes, it's referenced in both paragraphs 26 and 27 (I hadn't
noticed that before). And footnote 31 has the same wording, and is
referenced in paragraph 9 (there it refers to corresponding signed
and unsigned integer types).
When you say "general" how general do you mean ? Even outside the
present discussion ? And on what basis has this consensus been formed ?

I've never seen any suggestion, other than yours, that "same"
is used in some intransitive sense here.

Have you had or seen the same discussion elsewhere ? If not then using
the expression "general consensus" seems like an exaggeration to me.
Even after reading what
you've written about it, the idea doesn't make any sense to me.
If that were the intent, it would only make sense to use a word
other than "same".

Oh absolutely. I also believe that different words than "overflow" and
"byte" should have been used.
[...]
Usual meaning minus the implication of transitivity.

The usual meaning of "same" is transitive. In common English usage, it
just doesn't make any sense to say that A is the same as B, and B is the
same as C, but A is not the same as C. Similarity can certainly be
non-transitive; sameness cannot.

If you were to suggest a mathematical relation that's like equality
"minus the implication of transitivity", I would be equally at a
loss to understand what you have in mind.

What I have in mind is that SRAR() may not be transitive.
The footnote has problems. They're not caused by the use of the word
"same".

Of course not. A word on its own won't cause problems , it's the
combination of words which might do. I note also that it wasn't me who
focused on the meaning of "same" , it was others who put it at a
central place in their argumentation. For me the central question is
what the properties of the SRAR() relation are and the right way to
approach the question is by considering what's useful for programming
not what the ordinary meaning of some specific word is.
 
S

Spiros Bousbouras

What I consider to be the usual meaning of "same" is rendered almost
completely non-existent by removing transitivity. Whatever it is that
you think is left of the idea after removing that feature needs to be
explained in considerably more detail than the above paragraph.

The key issue is that SRAR() may not be transitive. That's the only
explanation I can offer.
More to the point, the key flaw in the footnote is neither the symmetry
nor the transitivity of SRAR();

The properties of SRAR() is the key issue.
it's the failure to keep in mind that
there are features of a type other than it's representation and
alignment which can affect the interchangeability with another type.

Also the failure to bring that fact to the reader's attention.
No, it is the phrase "is meant to imply" that leads to the problems;
"same" is just an innocent bystander.

Since you think that it unambiguously determines the properties of
SRAR() then you certainly can't consider it an innocent bystander.
Larry Jones has posted a message
in another branch of this thread that describes the intended meaning.
Keith has suggested that more appropriate wording to cover the intended
meaning would have used the phrase "recommended practice"; I agree.
There's no need to assume that "same" was intended to convey a meaning
almost completely divorced from it's normal one.

After Larry Jones's latest intervention perhaps not. But I'd rather he
post some code to make it clearer what the intention is.
I can't even imagine what "same" would mean if it were neither symmetric
nor transitive. Without those two features, I would strongly recommend
using some entirely different English word for whatever concept it is
that you're trying to describe - perhaps "similar"?

I have already used different words. I have said
*** SRAR() may not be transitive ***.
You don't see any mention of "same" in that phrase , do you ?
Though it does have
symmetry, it lacks transitivity, which would probably be sufficient.
However, a requirement that two type have "similar representation and
alignment" would be so vague as to be completely useless, and almost
completely untestable - but I think that fault is inherent in any
alternative definition for "same" which abandons either transitivity or
symmetry.

Could you explain the concept in more detail?

Not really and in any case I'm kind of fed up discussing the meaning of
"same" in the footnote. As I've just said in [1] I don't consider it
the right approach to interpreting the footnote. For me much more
relevant is the question I ask above :

Would it be guaranteed to be true without assuming that
SRAR() is symmetric and transitive ?

The question refers to code which has been snipped when it shouldn't
have but I'm also fed up posting the code again and again.


[1] <[email protected]>
http://groups.google.com/group/comp.lang.c/msg/81e47aa3bea48dcc?dmode=source
 
D

David Thompson

It is, but having the "same representation and alignment requirements"
is not sufficient for two types to be compatible with each other, nor to
ensure that there's an implicit conversion from one to the other.

Now, "The same representation and alignment requirements are meant to
imply interchangeability as arguments to functions, return values from
functions, and members of unions", but even interchangeable types are
not the same thing as compatible types.
Almost conversely, there are cases where types are compatible without
knowing that the representation is the same. In particular an array of
unspecified bound is compatible with any fixed bound of the same
element type, and in C99 also all VLAs of the same element type; and a
forward-declared (tag-only) struct or union is compatible with the
later completed one (but since the former is incomplete, it can be
used only to declare pointers, functions, and externals).

(Plus, as per another thread, K&R1-declared function types can be
compatible without being truly the same, but functions don't have
representations because they aren't data -- in C.)
Also, that footnote is not normative, and while it is "meant to imply
...", it does not actually imply it. Two types, with exactly the same
representation and alignment, could fail to be interchangeable for those
purposes if an implementation choses to treat them differently, for
instance by passing them in function calls by different mechanisms. The
fact that they are not compatible types is sufficient to allow such a
decision.

However, for pointer to character vs void, and signed vs unsigned
integer in their common range, 6.5.2.2p6 normatively requires
interchangeability for K&R1-style calls, and since on most
implementations the callers can be compiled separately (and later)
I see no way to accomplish this without full interchangeability.

7.15.1.1p2 similarly requires it for varargs.
 
J

James Kuyper

On Tue, 22 Mar 2011 21:45:42 -0400


The key issue is that SRAR() may not be transitive. That's the only
explanation I can offer.

Then you've failed to explain it. There's infinitely many possible
intransitive relationships between two C types; but there's not a single
one them for which I would consider "same representation and alignment"
a sane description. You don't have to describe to us the actual
relationship that you thought the committee meant to describe; if you're
not sure what that relationship was. It just has to be an precisely
described example of a relationship that would fit the context.

I need that description so I can ask you my next question: "How in the
world could you possibly imagine that the committee might describe that
relationships by saying 'same representation and alignment'?".

Alternatively, your example might make the answer to that question so
clear to me that I won't have to ask it - but that seems unlikely at
this point.
The properties of SRAR() is the key issue.

It's an important issue for you. Those properties are irrelevant to the
problem with that footnote, since that problem can be demonstrated
without any reference to the transitivity or symmetry of SRAR.
Also the failure to bring that fact to the reader's attention.

That's not a separate issue. Failure to bring a fact to the reader's
attention is a pretty much inevitable consequence of failing to think
about the fact in the first place.

....
Since you think that it unambiguously determines the properties of
SRAR() then you certainly can't consider it an innocent bystander.

But the problem is not the properties of SRAR, but rather the additional
issues that were not even mentioned while describing SRAR. Granted, I
believe that the issues that weren't mentioned, are issues not covered
by SRAR. However, my belief that those issues are not covered by SRAR
has nothing to do with the word "same", it has to do with the words
"representation" and "alignment". Neither of those words can be
stretched to cover such issues as which registers are used to pass
values to and from a function during a function call. Suggesting a
bizarre alternative meaning of "same" is not sufficient to stretch the
concept to cover those issues.
After Larry Jones's latest intervention perhaps not. But I'd rather he
post some code to make it clearer what the intention is.

Me too. It seems to me that "interchangeability" inherently implies
constraining the range of behavior under some situations which currently
have undefined behavior. I'd appreciate knowing whether or not that
understanding matches the committee's intent.

....
I have already used different words. I have said
*** SRAR() may not be transitive ***.
You don't see any mention of "same" in that phrase , do you ?

Yes, I do. The capital S in "SRAR" is an abbreviation for "same". The
only definition provided by the standard is exactly four words long, one
of which is "same". Any interpretation of that phrase which drops the
transitivity implied by the word "same" has a meaning that I can't wrap
my head around. If you care whether or not anyone has any idea what it
is you're talking about, you have to explain the idea better than simply
saying it's not transitive.

....
Not really and in any case I'm kind of fed up discussing the meaning of
"same" in the footnote. As I've just said in [1] I don't consider it
the right approach to interpreting the footnote. For me much more
relevant is the question I ask above :

Would it be guaranteed to be true without assuming that
SRAR() is symmetric and transitive ?

No. The faults that prevent it from being true would still remain,
whether or not SRAR were symmetric and transitive.
The question refers to code which has been snipped when it shouldn't
have but I'm also fed up posting the code again and again.

The code you've posted is guaranteed to return 1 because of the rules
for conversions between the different pointer types. Section 6.3.2.3p7,
and particularly the last sentence of that paragraph, is the key
reference for that conclusion. SRAR and interchangeability have nothing
to do with it. It's guaranteed to return 1 even on implementations where
they are NOT interchangeable. It would still be guaranteed to return 1
even if the standard were changed to allow those pointer types to have
completely unrelated representations, so long as it continued to say
what it currently says in 6.3.2.3p7. What it says in that clause does
imply that all three character types must have an alignment of 1, and
therefore the same alignment, but that's only one half of SRAR.
 
J

James Kuyper

Oh yes, that footnote has been the subject of many previous discussions,
both here and on comp.std.c. Search for the exact phrase "is meant to
imply", if you want to review them.
Have you had or seen the same discussion elsewhere ? If not then using
the expression "general consensus" seems like an exaggeration to me.

The consensus of the numerous previous discussions has, indeed, been as
Keith describes, though I'm not entirely sure "consensus" is the right
word for it. That word implies fewer and less strongly felt
disagreements than I've seen about this issue.

However, the idea that an extremely unusual meaning for "same" was
intended when the committee wrote "same representation and alignment"
is, to the best of my knowledge, your own completely unique contribution
to this discussion. The consensus has not been previously tested against
that hypothesis. Unless and until you explain the concept more clearly,
I think it's extremely unlikely to change that consensus.

....
What I have in mind is that SRAR() may not be transitive.

Yes, but can you describe what it would mean, with transitivity removed?
Could you give an example of a possible non-transitive meaning for SRAR?
The meaning of the phrase seems pretty clear, until you remove
transitivity - then I have no idea what it could possibly mean, nor why
any sane person would use the word "same" to describe a relationship
that wasn't transitive.

....
Of course not. A word on its own won't cause problems , it's the
combination of words which might do. I note also that it wasn't me who
focused on the meaning of "same" , it was others who put it at a
central place in their argumentation.

You made transitivity central to your discussion; since transitivity is
a trivial consequence of using the word "same" in anything that even
remotely resembles it's ordinary meaning, your questioning of
transitivity inherently focuses attention on the word "same".
 
L

lawrence.jones

Keith Thompson said:
Is the pdf created with a tool that numbers the footnotes automatically?

Yes, it's created with groff using the mm macros.
(I see that both the C99 standard and n1256.pdf were created by "Acrobat
Distiller Command 3.0 for HP-UX A.09.01 and later (HPPA)"; I've never
used it myself.)

That's because they are, in a sense, the same PDF file. Once, long ago,
I used that tool to convert the PostScript output from groff to PDF and
then created all the bookmarks by hand. Since then, I've simply
replaced all the pages to create newer versions in order to avoid having
to recreate the bookmarks again. Replacing pages doesn't change the
"created by" comment.
Speaking of the pdf, how difficult would it be to have index entries
link to the referenced text?

The current version of groff has infrastructure to enable it, but it
hasn't been integrated with the mm macro set. There have also been
issues with newer versions of both groff itself and the mm macro set
which cause them to misformat the document. To date, I've been too busy
just trying to get all the content correct to spend time debugging and
enhancing the formatting tools.
 
L

lawrence.jones

Spiros Bousbouras said:
The footnotes don't imply that interchangeability is required, they say
that it is intended to work.

Could you show some code which is intended to work ?[/QUOTE]

As one example:

file1.c:

int f(usigned u)
{
return u;
}

file2.c:

#include <stdio.h>
extern unsigned f(int);

int main(void)
{
printf("%d\n", f(10));
return 0;
}

This code exhibits undefined behavior because the declaration of f in
file2 is not compatible with the definition in file1 (both the parameter
types and return types are incompatible) , so an implementation is not
required to behave in any particular way, but the code "should" work and
print "10". If not, the implementation may still conform, but it's
"unfriendly" at best.
 
S

Spiros Bousbouras

Then you've failed to explain it. There's infinitely many possible
intransitive relationships between two C types; but there's not a single
one them for which I would consider "same representation and alignment"
a sane description.

Which would make it a "damn poor choice of terminology" as I said earlier.
But you seem convinced that whatever other errors the committee members
might have made , they would not make this particular one , they would
never use the word "same" to describe a relation which is not
transitive. My view is that people have made worse errors so why not
this one ?
You don't have to describe to us the actual
relationship that you thought the committee meant to describe; if you're
not sure what that relationship was. It just has to be an precisely
described example of a relationship that would fit the context.

A relation between 2 types which is symmetric and therefore would
guarantee that

int foo2(void) {
char c = 0 , *p = &c ;
void *v = (void *) p ;

return p == (char *)v ;
}

always returns 1. Since you have convinced me that the foo() which I
posted earlier ([1]) always returns 1 regardless of the transitivity of
SRAR() , I don't see any point in having SRAR() be transitive which
makes it even more uncertain how "same" should be understood. But
symmetry of SRAR() is still important for the code above and that's an
argument in favour of "same" having its usual meaning.
I need that description so I can ask you my next question: "How in the
world could you possibly imagine that the committee might describe that
relationships by saying 'same representation and alignment'?".

People make mistakes.
Alternatively, your example might make the answer to that question so
clear to me that I won't have to ask it - but that seems unlikely at
this point.


It's an important issue for you. Those properties are irrelevant to the
problem with that footnote, since that problem can be demonstrated
without any reference to the transitivity or symmetry of SRAR.

So you say but I don't see it.
That's not a separate issue. Failure to bring a fact to the reader's
attention is a pretty much inevitable consequence of failing to think
about the fact in the first place.

Ok , I shouldn't have said "Also". So perhaps they did think about it
and they still decided to leave the footnote as it is for whatever
reason. Perhaps their only omission was not realising that the footnote
is misleading as it is written.
But the problem is not the properties of SRAR, but rather the additional
issues that were not even mentioned while describing SRAR. Granted, I
believe that the issues that weren't mentioned, are issues not covered
by SRAR. However, my belief that those issues are not covered by SRAR
has nothing to do with the word "same", it has to do with the words
"representation" and "alignment". Neither of those words can be
stretched to cover such issues as which registers are used to pass
values to and from a function during a function call. Suggesting a
bizarre alternative meaning of "same" is not sufficient to stretch the
concept to cover those issues.

Why the standard would have anything whatsoever to say about which
registers are used to pass values to functions ? C is supposed to
abstract away from such stuff.
Me too. It seems to me that "interchangeability" inherently implies
constraining the range of behavior under some situations which currently
have undefined behavior. I'd appreciate knowing whether or not that
understanding matches the committee's intent.

So your theory is that if footnote 39 of 6.2.5 p26 did not have the
flaw you say it has then certain behaviors which now are undefined ,
would become defined in those implementations which would follow the
recommendation in the footnote. Do you have some specific code in mind
which would become defined ?
Yes, I do. The capital S in "SRAR" is an abbreviation for "same".

You know what ? I had completely forgotten about that. But I think this
is actually a good thing. Because all I see now is an abstract relation
and the question is what are the properties of the relation and what is
the correspondence between the relation and the semantics of the language.
The
only definition provided by the standard is exactly four words long, one
of which is "same".

Actually it was me who defined SRAR.
Any interpretation of that phrase which drops the
transitivity implied by the word "same" has a meaning that I can't wrap
my head around.

So I suggest that you stop thinking about "same" and think in terms of
"SRAR" without paying attention to which words inspired the name
"SRAR". In fact , since you say that the flaw you think footnote 39 has
is independent from whether SRAR() is symmetric or transitive , you
actually don't lose anything by forgetting about "same" and what
properties it may imply.
If you care whether or not anyone has any idea what it
is you're talking about, you have to explain the idea better than simply
saying it's not transitive.

I do and that's why I posted some code. So far I'm the only one who
has.
Not really and in any case I'm kind of fed up discussing the meaning of
"same" in the footnote. As I've just said in [1] I don't consider it
the right approach to interpreting the footnote. For me much more
relevant is the question I ask above :

Would it be guaranteed to be true without assuming that
SRAR() is symmetric and transitive ?

No. The faults that prevent it from being true would still remain,
whether or not SRAR were symmetric and transitive.

The context appears in [1]. According to "The code you've posted is
guaranteed to return 1" below, the answer should be yes.
The code you've posted is guaranteed to return 1 because of the rules
for conversions between the different pointer types. Section 6.3.2.3p7,
and particularly the last sentence of that paragraph, is the key
reference for that conclusion. SRAR and interchangeability have nothing
to do with it. It's guaranteed to return 1 even on implementations where
they are NOT interchangeable. It would still be guaranteed to return 1
even if the standard were changed to allow those pointer types to have
completely unrelated representations, so long as it continued to say
what it currently says in 6.3.2.3p7. What it says in that clause does
imply that all three character types must have an alignment of 1, and
therefore the same alignment, but that's only one half of SRAR.

Good point. It didn't occur to me that the last sentence of 6.3.2.3 p7
implies that all char types have alignment of 1.


[1] <[email protected]>
http://groups.google.com/group/comp.lang.c/msg/2da29e273c3f1dc6?dmode=source
 
S

Spiros Bousbouras

On Tue, 22 Mar 2011 16:45:57 -0400


Could you show some code which is intended to work ?

As one example:

file1.c:

int f(usigned u) unsigned

{
return u;
}

file2.c:

#include <stdio.h>
extern unsigned f(int);

int main(void)
{
printf("%d\n", f(10));
return 0;
}

This code exhibits undefined behavior because the declaration of f in
file2 is not compatible with the definition in file1 (both the parameter
types and return types are incompatible) , so an implementation is not
required to behave in any particular way, but the code "should" work and
print "10".[/QUOTE]

I don't see why it should work. "Morally" the code simply doesn't make
sense , why should one expect any particular behavior regardless of
what the standard specifies ? And it's not just the undefined behavior.
Even if file2.c had correct declaration the code still is suspect
because the "return u" does assignment from unsigned to signed int.
Obviously with the value 10 it doesn't matter but even if I saw file1.c
on its own , I would still consider the code suspicious.

So I don't think it should print "10" , it should print a warning. If
footnote 31 of 6.2.5 p9 and footnote 39 of 6.2.5 p26 exist to encourage
implementations to accept such nonsense then the 2 footnotes should be
removed IMO.
If not, the implementation may still conform, but it's
"unfriendly" at best.

On the contrary , I would consider dodgy an implementation which
doesn't warn me about the code. I actually tried a modified version
with file2.c being

#include <stdio.h>
extern unsigned f(int);

int main(void) {
f(10) ;
//printf("%d\n", f(10));
return 0;
}

gcc , tcc and Sun Studio 12 c99 will all warnings turned on do not
complain. Shocking. But Sun Studio 12 lint and splint both point out
both type mismatches.

And since the discussion has been mainly centred around footnote 39 of
6.2.5 p26 here's a version of the code for that footnote:

file1.c:
unsigned char * f(char *p) {
return (unsigned char *)p ;
}

file2.c
extern char * f(unsigned char*) ;

int main(void) {
char c = 0 ;
f((unsigned char*)&c) ;
return 0 ;
}

Would you also consider unfriendly an implementation which rejects this
code ? I wouldn't.

The 3 compilers I mentioned above again accept the code silently but
the 2 lints produce the appropriate warnings.
 
S

Spiros Bousbouras

Oh yes, that footnote has been the subject of many previous discussions,
both here and on comp.std.c. Search for the exact phrase "is meant to
imply", if you want to review them.

Then why the hell didn't someone say so much earlier ? It might have
saved us all a lot of time.

[...]
You made transitivity central to your discussion; since transitivity is
a trivial consequence of using the word "same" in anything that even
remotely resembles it's ordinary meaning, your questioning of
transitivity inherently focuses attention on the word "same".

No , it focuses attention on what purpose relevant to implementors or
programmers the footnote is meant to serve and whether that purpose
requires SRAR to be transitive.
 
J

James Kuyper

On Thu, 24 Mar 2011 09:03:51 -0400


Then why the hell didn't someone say so much earlier ? It might have
saved us all a lot of time.

I don't normally cite the existence of a consensus of opinion as an
argument in favor of a given point of view. Citations from the standard
are what's really important, not people's opinions about what they mean.

....
No , it focuses attention on what purpose relevant to implementors or
programmers the footnote is meant to serve and whether that purpose
requires SRAR to be transitive.

I believe that the intended purpose depends upon "sameness": that is,
the use of EXACTLY the same relationship between bit patterns and
values, and possession of EXACTLY the same alignment. These things allow
type punning; anything less than perfect "sameness" would not serve any
useful purpose. A relationship similar to "sameness", but sufficiently
different to remove transitivity, would necessarily be only a similarity
relationship, and as such, would not allow type punning.
 
J

James Kuyper

On Thu, 24 Mar 2011 09:02:42 -0400


Which would make it a "damn poor choice of terminology" as I said earlier.
But you seem convinced that whatever other errors the committee members
might have made , they would not make this particular one , they would
never use the word "same" to describe a relation which is not
transitive. My view is that people have made worse errors so why not
this one ?

Because I can't imagine what they might possibly have meant by "same
representation and alignment" that was NOT accurately described by that
phrase. If you'd provided a possible alternative meaning, I might be
able to evaluate the plausibility of the idea that they actually
intended that alternative. But all you've been able to say is "not
transitive", without giving any details about what this intransitive
alternative meaning might be.
You don't have to describe to us the actual
relationship that you thought the committee meant to describe; if you're
not sure what that relationship was. It just has to be an precisely
described example of a relationship that would fit the context.

A relation between 2 types which is symmetric and therefore would
guarantee that

int foo2(void) {
char c = 0 , *p =&c ;
void *v = (void *) p ;

return p == (char *)v ;
}

always returns 1. Since you have convinced me that the foo() which I
posted earlier ([1]) always returns 1 regardless of the transitivity of
SRAR() , I don't see any point in having SRAR() be transitive which
makes it even more uncertain how "same" should be understood. But
symmetry of SRAR() is still important for the code above and that's an
argument in favour of "same" having its usual meaning.

Your code doesn't involve the representations in any way that depends
upon their sameness; it only involves conversions, which can preserve
all of the relevant properties, even if different representations are
used by the different types.
People make mistakes.

Yes, but they're generally not random mistakes; there are reasons the
mistakes are made, which can be inferred in many cases from the nature
of the mistake. To me, it's entirely plausible that someone might have
made the mistake of thinking that "same representation and alignment"
was sufficient to ensure interchangeability - you don't understand yet
my explanation of how this is a mistaken conclusion, and I (sort-of)
understand why; they might have made a similar mistake.
However, I can't figure out plausible way for someone writing "same"
when they meant "similar", nor any plausible reason why they might have
meant "similar" when sameness is the characteristic that gives this
guarantee what little value it might have.

....
So you say but I don't see it.

I've been trying and failing to find spare time to write up a response
to your earlier question on this matter for several days now. It's a
complicated task and I've had a lot of distractions. I'll try to get it
out sometime this weekend.

....
Why the standard would have anything whatsoever to say about which
registers are used to pass values to functions ? C is supposed to
abstract away from such stuff.

It shouldn't. My real preference would be for the standard to merely
require interchangeability (and provide a precise definition of what
that means), and leave the details of how interchangeability can be
ensured up to the implementation. SRAR would merely be a derivable
feature of the implementation, not a requirement in itself.

....
So your theory is that if footnote 39 of 6.2.5 p26 did not have the
flaw you say it has then certain behaviors which now are undefined ,
would become defined in those implementations which would follow the
recommendation in the footnote. Do you have some specific code in mind
which would become defined ?

Yes, and I'll provide it soon, when I don't have a wife yelling at me
that it's time to get to bed.
So I suggest that you stop thinking about "same" and think in terms of
"SRAR" without paying attention to which words inspired the name
"SRAR". In fact , since you say that the flaw you think footnote 39 has
is independent from whether SRAR() is symmetric or transitive , you
actually don't lose anything by forgetting about "same" and what
properties it may imply.

If I don't pay attention to the four words "same representation and
alignment", I have absolutely no idea what it means; you've provided
only the vaguest clues to a possible alternative meaning. If I do pay
attention to them, I can't figure out what alternative you could
possibly be implying. Maybe it's just a failure of my imagination; but
if you can imagine such an alternative, could you please describe it?
I do and that's why I posted some code. So far I'm the only one who
has.

You have not yet explained the alternative interpretation of SRAR that
allows the behavior of that code to be in question.

....
No. The faults that prevent it from being true would still remain,
whether or not SRAR were symmetric and transitive.

The context appears in [1]. According to "The code you've posted is
guaranteed to return 1" below, the answer should be yes.

The code can be guaranteed to be true despite interchangeability not
being a valid conclusion to reach from SRAR, because the code doesn't
involve interchangeability; not as I understand that term.
 

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,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top