[cpp-threads] C (not C++) background to C++ 3.9.3/1

Nick Maclaren nmm1 at cus.cam.ac.uk
Wed Mar 1 18:53:47 GMT 2006


"Peter Dimov" <pdimov at mmltd.net> wrote:
> 
> Let's suppose, for the sake of argument, that I agree that one _could_ read 
> 3.9.3/1 your way; but to argue that it _clearly_ speaks of value 
> representation, when alignment requirements are mentioned in the same 
> sentence - values don't have alignment, objects do - seems to go a bit too 
> far.

Well, yes, it might be - if C++ had not taken that wording lock,
stock and barrel from C89.  And C89 actually REQUIRES arguments to
have a different object type from their syntactic type under some
circumstances.  C++ did not copy those circumstances, but how that
can change the meaning of unchanged words is beyond me ....

I append a script that shows the effect.  The point is that, in
order to enable mixed K&R and ISO function declarations, arguments
MUST use their syntactic type for the value representation and their
promoted type (or better) for the object representation; if I recall,
there was an interpretation that said that the compiler had to do a
double conversion if necessary (the issue becomes germane for float
arguments).

Look at the declarations and use of joe in fred.c and frederick.c
and try to work out how that can be done any other way.

And PLEASE don't think that I am justifying such a specification!


Script:

#!/bin/sh

cat << 'input' > fred.c
#include <stdio.h>
#include <limits.h>

extern void joe (), bert (void);

int main (void) {
    char c = 123, d = 98;

    printf("UCHAR_MAX = %d, CHAR_BIT = %d, sizeof(char) = %d\n",
        UCHAR_MAX,CHAR_BIT,sizeof(char));
    joe(c,d);
    bert();
    return 0;
}
input

sed 's/char c = 123, d = 98/int c = 12345, d = 9876/; s/(char, char)/(int, int)/' fred.c > frederick.c

cat << 'input' > bert.c
extern void joe (char, char);

void bert (void) {
    char c = 123, d = 98;
    
    joe(c,d);
}
input

sed 's/char c = 123, d = 98/int c = 12345, d = 9876/; s/(char, char)/(int, int)/' bert.c > albert.c

cat << 'input' > joe.c
#include <stdio.h>

void joe (char c, char d) {
    printf("sizeof(c) = %d, sizeof(d) = %d, c = %d, d = %d\n",
        sizeof(c),sizeof(d),c,d);
}
input

sed 's/char c, char d/int c, int d/' joe.c > joseph.c

cc -Wall -ansi -pedantic -c fred.c frederick.c bert.c albert.c joe.c joseph.c
cc fred.o bert.o joe.o
a.out
cc frederick.o albert.o joseph.o
a.out


Results:

UCHAR_MAX = 255, CHAR_BIT = 8, sizeof(char) = 1
sizeof(c) = 1, sizeof(d) = 1, c = 123, d = 98
sizeof(c) = 1, sizeof(d) = 1, c = 123, d = 98
UCHAR_MAX = 255, CHAR_BIT = 8, sizeof(char) = 1
sizeof(c) = 4, sizeof(d) = 4, c = 12345, d = 9876
sizeof(c) = 4, sizeof(d) = 4, c = 12345, d = 9876


Regards,
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QH, England.
Email:  nmm1 at cam.ac.uk
Tel.:  +44 1223 334761    Fax:  +44 1223 334679



More information about the cpp-threads mailing list