EBCDIC <--> ASCII conversion

Richard A. O'Keefe ok at goanna.cs.rmit.oz.au
Tue Oct 9 16:45:28 AEST 1990


In article <12609 at blia.BLI.COM>, jeffb at blia.BLI.COM (Jeff Beard) writes:
> static char dummy[] = {0};  /* for EOF index */
> char atoe[] = {
>    };

This isn't going to work.  A compiler may insert any amount of padding
after dummy[].  It may even put atoe[] at a lower address than dummy[].
(There is nothing to stop a compiler sorting top-level variables into
alphabetic order...)  'static' and 'extern' variables might well go into
different sections.  And so on.

Even
	struct {
	    char eof_code;
	    char atoe[256]
	} = { 0,
	    /* atoe values as before */
	}
isn't going to work in general because a compiler may insert padding
between fields.

The only method that is going to work is
	char RAWatoe[] =
	    {	0,
		/* atoe values as before */
	    };
	char *atoe = RAWatoe+1;
	/* OR
	#define atoe(x) RAWateo[1+(x)]
	*/

> static char dummy2[] = {0};  /* for EOF index */
> char etoa[] = {
> #ifdef OLDC
>    0321          , 0322 /*  ~  */, 0163 /* 's' */, 0164 /* 't' */,
> #else  OLDC
>    0321          , 0176 /*  ~  */, 0163 /* 's' */, 0164 /* 't' */,
> #endif OLDC
>    };

This one isn't going to work for an additional reason:  the ANSI C
standard doesn't accept tokens after #else or #endif, and the ANSI
standard doesn't accept it because it wasn't universal practice.
For example, the C compiler for UNIX V.3 chokes on them.

The two following 'ed' commands may be useful to people who still
have to fix this in their code.  (My code used to be _full_ of this
stuff, but I don't blame ANSI, it really wasn't portable.)

	1,$ s:^\([ \t]*#[ \t]*else[ \t][ \t]*\)\([^ \t/].*\)$:\1/*\2*/:
	1,$ s:^\([ \t]*#[ \t]*endif[ \t][ \t]*\)\([^ \t/].*\)$:\1/*\2*/:

-- 
Fear most of all to be in error.	-- Kierkegaard, quoting Socrates.



More information about the Comp.lang.c mailing list