Re: Simplicity has a future



Richard Heathfield wrote:
Harald van D?k said:

You claimed the program was valid C.

It is.

Silly me for assuming you would refer to an older standard without stating
so.

It is certainly silly to assume that everyone has started using C99 even
though almost nobody has a conforming C99 compiler.

I didn't assume that, nor did I claim to.

That aside, though, your rules are obviously intentionally
unreasonable, as it is entirely possible to modify your program to make
it valid C++ without modifying either its "essential character" or its
output.

Go on then.

Your original program:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define a(b) #b
#define SPACE ' '

int main(void)
{
const char *asm = a(asm);
const char *protected = a(protected);
const char *using = a(using);
const char *b[28] = {0};
char title__of__the__program[81] =
"C to C++ Translation\nONLY extra casts and renaming"
" of variables are allowed.\n\n\n\n\n";
auto i = strlen(protected) -
(sizeof SPACE //* we need a space\
in here somewhere */ sizeof (int
) + strlen(asm) + strlen(using));

if(strcmp(asm, "asm") != 0 || strcmp(protected, "protected") != 0 ||
strcmp(using, "using") != 0)
{
puts("Error!");
return EXIT_FAILURE;
}

b[0] = asm + 1;
b[1] = b[0] - 1;
b[2] = protected + 8;
b[4] = b[2] - 8;
b[5] = b[4] + 1;
b[6] = b[5] + 1;
b[7] = using + 4;
b[8] = b[5];
b[9] = b[0] - 1;
b[10] = b[0] + 1;
b[11] = b[10];
b[12] = b[2] - 4;
b[13] = b[12] - 3;
b[14] = b[0];
b[16] = b[2];
b[17] = b[16] - 6;
b[19] = b[7] - 1;
b[20] = b[2] - 6;
b[21] = b[20] + 1;
b[23] = b[7] - 4;
b[24] = b[23] + 1;
b[25] = b[2] - 4;
b[27] = b[25] + 1;

printf("%.*s\n",
(int)sizeof title__of__the__program,
title__of__the__program);

while(i < sizeof b / sizeof b[0])
{
if(b[i] != NULL)
{
if(i == sizeof(char) / sizeof SPACE ||
i == sizeof b / sizeof b[0] - 1)
{
putchar(toupper((unsigned char)
b[i][sizeof(char)/sizeof SPACE]));
}
else
{
putchar(tolower((unsigned char)
b[i][sizeof(char)/sizeof SPACE]));
}
}
else
{
putchar(SPACE);
}
i += strlen(protected) - (strlen(asm) + strlen(using));
}

putchar('.' * sizeof SPACE / sizeof(int));
putchar('\n');

return 0;

}

The changes I made (line numbers refer to the original code, not the
modified code):

Add #include <ctype.h> before line 4.

Change ' ' to ((int) ' ') on line 6.

Add before line 8:
#define asm renamed_asm
#define protected renamed_protected
#define using renamed_using

Change title__of__the__program to title on lines 14, 54 and 55.

Change on lines 14 and 15:
"C to C++ Translation\nONLY extra casts and renaming"
" of variables are allowed.\n\n\n\n\n"
to
{ 'C', ' ', 't', ...
.... '.', '\n', '\n', '\n', '\n', '\n' }

Change auto to auto int on line 17.

Change // to / / on line 18.

Please tell me if any part of this, according to you, changes the
essential character, or makes it invalid C90, or if this isn't enough
to make it valid C++.

.



Relevant Pages

  • Re: Simplicity has a future
    ... const char *protected = a; ... (sizeof SPACE //* we need a space\ ... in here somewhere */ sizeof (int ... It's perfectly legal C90. ...
    (comp.lang.c)
  • Re: Simplicity has a future
    ... And then compile it, I guarantee that the C++ version won't be slower or ... const char *protected = a; ... (sizeof SPACE //* we need a space\ ... in here somewhere */ sizeof (int ...
    (comp.lang.c)
  • Re: Simplicity has a future
    ... I guarantee that the C++ version won't be slower or ... const char *protected = a; ... (sizeof SPACE //* we need a space\ ... in here somewhere */ sizeof (int ...
    (comp.lang.c)
  • Re: Simplicity has a future
    ... And then compile it, I guarantee that the C++ version won't be slower or ... const char *protected = a; ... (sizeof SPACE //* we need a space\ ... in here somewhere */ sizeof (int ...
    (comp.lang.c)