Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!samsung!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: EBCDIC <--> ASCII conversion Summary: Nits picked Message-ID: <3935@goanna.cs.rmit.oz.au> Date: 9 Oct 90 06:45:28 GMT References: <1756@dinl.mmc.UUCP> <1990Oct2.185212.25161@athena.mit.edu> <12609@blia.BLI.COM> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 54 In article <12609@blia.BLI.COM>, jeffb@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.