Re: A[x][y][z]
- From: Roberto Waltman <usenet@xxxxxxxxxxxx>
- Date: Fri, 30 Sep 2005 13:33:08 -0400
On 30 Sep 2005 03:28:05 -0700, sterten@xxxxxxx wrote:
>what I had in mind and meant with "pre-compiler" or "preprocessor"
>is a small utility which reads the C-"source" containing A[x,y]
>or int A[n] and converts it into another C-source-file
>where A[x,y] is converted into A[x][y] and int A[n]; into
>int A[n+1] and maybe some other things too.
>
>This can't be so difficult to write and probably already
>exists somewhere ?!?
(A) Converting A[x,y] into A[x][y]
That could work only under the assumption that an expression such as
A[x,y] will never occur in you code.
How can a preprocessor know if you mean a two-dimensional array or a
unidimensional one, where the comma operator is used to generate the
index?
A[z]
A[y,z]
A[x,y,z]
A[p,q,r,s,t,u,v,w,x,y,z]
These are all valid C expressions, all of them selecting the 'z'th
element of the unidimensional array A.
(B) Converting int A[n] into A[n+1];
(b.1) While that's more easily done, it may have many undesirable side
effects.
The loop (for i=0; i < MAX; i++) {...A[i]...} is a very well C known
idiom, while (for i=1; i<= MAX; i++) {...A[i]...} is not.
You can expect many "off by one" errors when using this approach with
existing code, or when linking your code with libraries expecting the
"C" way.
(b.2) Use C++. Use only the set of features common with C (*), so you
can fool yourself into thinking it is C, but define a set of classes
and overloaded [] operators providing the functionality you want.
(*) Yes, I know the "C is not a proper subset of C++" drill
Roberto Waltman
[ Please reply to the group, ]
[ return address is invalid. ]
.
- References:
- A[x][y][z]
- From: sterten
- Re: A[x][y][z]
- From: Keith Thompson
- Re: A[x][y][z]
- From: Keith Thompson
- Re: A[x][y][z]
- From: sterten
- A[x][y][z]
- Prev by Date: Sprintf .....
- Next by Date: Re: Why googlers never quote and never will (Was: Re: Universal (g)libc)
- Previous by thread: Re: A[x][y][z]
- Next by thread: Re: A[x][y][z]
- Index(es):