Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   A[x][y][z] (http://www.velocityreviews.com/forums/t439590-a-x-y-z.html)

sterten@aol.com 09-29-2005 02:57 PM

A[x][y][z]
 
it's awful in C with multi-dimension arrays.

A[x][y][z] is worse than A[x,y,z] ,

is someone successfully running the C-compiler from batch-file,
first converting all of the latter expressions
into the corresponding former ones and then compiling it ?

And while we're at it, this preprocessing utility should
also change array definitions like e.g.
int B[N];
into int B[N+1];
since B[N] would not be defined else, only B[0],B[1],..,B[N-1]


Chris Dollin 09-29-2005 03:11 PM

Re: A[x][y][z]
 
sterten@aol.com wrote:

> it's awful in C with multi-dimension arrays.


If you say so.

> A[x][y][z] is worse than A[x,y,z] ,


Is it?

> is someone successfully running the C-compiler from batch-file,
> first converting all of the latter expressions
> into the corresponding former ones and then compiling it ?
>
> And while we're at it, this preprocessing utility should
> also change array definitions like e.g.
> int B[N];
> into int B[N+1];
> since B[N] would not be defined else, only B[0],B[1],..,B[N-1]


My advice would be to write the code correctly in the first place.
`int B[N]` defines an N-element array. It just has weird indexing.
You may think - I certainly do - that 0-based indexing is the work
of the devil, but that is the choice made for C, and you're better
off working with it (and hence not contrary to the usual behaviour
of those here who might help you) than against it.

--
Chris "am I troll-caught?" Dollin
The software engineer's song: "who knows where the time goes".

Skarmander 09-29-2005 04:16 PM

Re: A[x][y][z]
 
sterten@aol.com wrote:
> it's awful in C with multi-dimension arrays.
>
> A[x][y][z] is worse than A[x,y,z] ,
>

<snip>
If you want Pascal, you know where to get it.

S.

Alexei A. Frounze 09-29-2005 06:59 PM

Re: A[x][y][z]
 
"Skarmander" <invalid@dontmailme.com> wrote in message
news:433c1373$0$11079$e4fe514c@news.xs4all.nl...
> sterten@aol.com wrote:
> > it's awful in C with multi-dimension arrays.
> > A[x][y][z] is worse than A[x,y,z] ,
> >

> If you want Pascal, you know where to get it.


Maybe Matlab is a better try? :)
Alex



Keith Thompson 09-29-2005 08:37 PM

Re: A[x][y][z]
 
sterten@aol.com writes:
> it's awful in C with multi-dimension arrays.


I don't disagree.

C doesn't actually have multi-dimensional arrays. It only has
one-dimensional arrays, but the element type can itself be an array
type; an array of arrays of arrays acts very much like a 3-dimensional
array.

> A[x][y][z] is worse than A[x,y,z] ,


It's fine once you get used to it. Note also that A[x,y,z] is also a
valid expression (though not one that you'd ever want to use). The
comma operator evaluates both operands and yields the result of its
right operand, so A[x,y,z] is equivalent to A[z] (assuming x and y
have no side effects).

And because of the relationship between arrays and pointers, the
actual meaning of A[x][y][z] can vary depending on whether A is an
array of arrays of arrays, or a pointer to an array of pointers to
arrays of pointers to arrays (I think I got that right), or any of a
number of other possibilities. The pointer implementation is actually
more common because it's more flexible.

> is someone successfully running the C-compiler from batch-file,
> first converting all of the latter expressions
> into the corresponding former ones and then compiling it ?


I sincerely hope not.

> And while we're at it, this preprocessing utility should
> also change array definitions like e.g.
> int B[N];
> into int B[N+1];
> since B[N] would not be defined else, only B[0],B[1],..,B[N-1]


And while you're at it, you can do things like:

#define IF if(
#define THEN ){
#define ELSE }else{
#define ELSEIF }else if(
#define ENDIF }

and pretend you're writing in a different language altogether. Except
that you're still really programming in C, with all the drawbacks that
implies, with a thin and fragile layer of a different syntax on top of
it.

People have tried this kind of thing, and it's invariably a bad idea.
The result is something that experienced C programmers won't be able
to read because it doesn't look like C, and experienced programmers in
other languages won't be able to read because it doesn't quite look
like anything else.

There is an underlying logic to the way C is designed. You might not
like it (there are things I dislike myself), but you really should try
to understand it before you try to mess with it.

If you want to program in C, you should learn C, with all its little
quirks. If you dislike C so much, you should pick a different
language.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.

sterten@aol.com 09-30-2005 05:51 AM

Re: A[x][y][z]
 
>> A[x][y][z] is worse than A[x,y,z] ,
>
>It's fine once you get used to it.


on German keyboards there is also the disadvantage that you have
to press the "altGr" key to get [] , which often makes typing
of math-programs difficult and erroneous. E.g. I often type
"}" instead of "]" and then it's hard to loacate the error.

....

>> is someone successfully running the C-compiler from batch-file,
>> first converting all of the latter expressions
>> into the corresponding former ones and then compiling it ?

>
>I sincerely hope not.


why ? Afraid others could improve their programming skills
and your own programs written in less advanced language
become less competitive ?

>> And while we're at it, this preprocessing utility should
>> also change array definitions like e.g.
>> int B[N];
>> into int B[N+1];
>> since B[N] would not be defined else, only B[0],B[1],..,B[N-1]

>
>And while you're at it, you can do things like:
>
> #define IF if(
> #define THEN ){
> #define ELSE }else{
> #define ELSEIF }else if(
> #define ENDIF }


these won't make notation much shorter or easier.
Although sometimes I wished the pre-compiler could
add things like "}" --> "} // next x"
It's hard in C to keep track of the nested levels of "{,}"

One other thing comes to mind, that is dynamical array definition.
Why can't I do : (or is there a way ?)
main(int argc,char*argv[]){
sscanf(argv[1],"%i",&n);
global int A[n];
}


>and pretend you're writing in a different language altogether.

Except
>that you're still really programming in C, with all the drawbacks

that
>implies, with a thin and fragile layer of a different syntax on top

of
>it.
>
>People have tried this kind of thing, and it's invariably a bad idea.



please give a link or a searchable keyword and let me decide by myself

>The result is something that experienced C programmers won't be able
>to read because it doesn't look like C, and experienced programmers

in
>other languages won't be able to read because it doesn't quite look
>like anything else.


you still have the output of the preprocessor which you could show
to these.

>There is an underlying logic to the way C is designed. You might not


>like it (there are things I dislike myself), but you really should

try
>to understand it before you try to mess with it.


you won't expect that it's so perfect that it can't be improved...

>If you want to program in C, you should learn C, with all its little
>quirks.


no. I only need some few commands. When you require people to
learn "all the little quirks" - that might keep them away from C

>If you dislike C so much, you should pick a different
>language.


Not "so much". And why isn't it allowed to improve something
no matter how good it is already ?

And BTW. strangely enough I get the same advice from these
assembly programmers and Basic programmers where I wanted
to introduce some C-elements.
Let's combine the goodies from each language !



-Guenter


Keith Thompson 09-30-2005 08:45 AM

Re: A[x][y][z]
 
sterten@aol.com writes:
> > > A[x][y][z] is worse than A[x,y,z] ,

> >
> > It's fine once you get used to it.

>
> on German keyboards there is also the disadvantage that you have
> to press the "altGr" key to get [] , which often makes typing
> of math-programs difficult and erroneous. E.g. I often type
> "}" instead of "]" and then it's hard to loacate the error.


(Please don't snip attributions. It's helpful if readers can tell who
wrote what.)

Ok. That's not a problem I've ever run into; I can't think of a good
solution. (Maybe you could define an editor macro?)

> > > is someone successfully running the C-compiler from batch-file,
> > > first converting all of the latter expressions
> > > into the corresponding former ones and then compiling it ?

> >
> > I sincerely hope not.

>
> why ? Afraid others could improve their programming skills
> and your own programs written in less advanced language
> become less competitive ?


Um, no. I just think it's a bad idea.

> > > And while we're at it, this preprocessing utility should
> > > also change array definitions like e.g.
> > > int B[N];
> > > into int B[N+1];
> > > since B[N] would not be defined else, only B[0],B[1],..,B[N-1]

> >
> > And while you're at it, you can do things like:
> >
> > #define IF if(
> > #define THEN ){
> > #define ELSE }else{
> > #define ELSEIF }else if(
> > #define ENDIF }

>
> these won't make notation much shorter or easier.
> Although sometimes I wished the pre-compiler could
> add things like "}" --> "} // next x"
> It's hard in C to keep track of the nested levels of "{,}"


What do you mean by "pre-compiler"? It sounds like you want something
that modifies your source code. A language-sensitive text editor
could probably do that kind of thing.

> One other thing comes to mind, that is dynamical array definition.
> Why can't I do : (or is there a way ?)
> main(int argc,char*argv[]){
> sscanf(argv[1],"%i",&n);
> global int A[n];
> }


There's no "global" keyword, but C99 does support variable-length
arrays.

> > and pretend you're writing in a different language
> > altogether. Except that you're still really programming in C, with
> > all the drawbacks that implies, with a thin and fragile layer of a
> > different syntax on top of it.
> >
> > People have tried this kind of thing, and it's invariably a bad idea.b

>
> please give a link or a searchable keyword and let me decide by myself


Sorry, I don't have any references. I understand that the original
Bourne shell used something like the ugly pseudo-Pascal
BEGIN/END/IF/ELSE macros, but I believe it's been corrected.

> > The result is something that experienced C programmers won't be
> > able to read because it doesn't look like C, and experienced
> > programmers in other languages won't be able to read because it
> > doesn't quite look like anything else.

>
> you still have the output of the preprocessor which you could show
> to these.


The preprocessor (if you mean the C preprocessor that's part of the
compiler) also expands #include directives and *all* macros, among
other things. The output isn't particularly legible.

> > There is an underlying logic to the way C is designed. You might
> > not like it (there are things I dislike myself), but you really
> > should try to understand it before you try to mess with it.

>
> you won't expect that it's so perfect that it can't be improved...


I didn't say that, or anything resembling it.

The C standard exists for a reason. It's certainly not perfect; there
are plenty of things I would have done differently. But it permits
consistency across programmers and implementations. If I write code
in C, any C programmer can read it. (Code is written for other
programmers as much as for the compiler.)

The English language has plenty of problems, and there are a lot of
changes I could suggest. I could invent an English-like language with
more logical spelling and grammar and a more consistent vocabulary.
But if I started writing in this new language, even if it's superior
to standard English, nobody would be able to understand me.

> > If you want to program in C, you should learn C, with all its little
> > quirks.

>
> no. I only need some few commands. When you require people to
> learn "all the little quirks" - that might keep them away from C


If you want to program in C without learning more than "some few
commands", I don't think we can help you.

> > If you dislike C so much, you should pick a different
> > language.

>
> Not "so much". And why isn't it allowed to improve something
> no matter how good it is already ?


Lots of people have tried to improve C. They do it by inventing new
languages (C++, C#, Java, several languages calling themselves D).

> And BTW. strangely enough I get the same advice from these
> assembly programmers and Basic programmers where I wanted
> to introduce some C-elements.
> Let's combine the goodies from each language !


The best way to do that would be to create a new coherent language.
You can even use C as the intermediate language generated by the
compiler (the original "cfront" implementation of C++ did this).

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.

sterten@aol.com 09-30-2005 10:28 AM

Re: A[x][y][z]
 

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 ?!?


Flash Gordon 09-30-2005 11:21 AM

Re: A[x][y][z]
 
sterten@aol.com wrote:

Provide context. I'm sure that one of two things is true:
1) You have already been given instructions on how to do this
2) You have been providing context.

In either case you have no excuse for not doing so now. There are plenty
of posts on the group giving instructions, so if you don't know how then
read yesterdays posts and you will find the instructions.

> 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 ?!?


It may well not be difficult, but I don't believe there is any *good*
reason for doing it for all the reasons Kieth and others have stated.

Some reasons are:
1) If you ran the code through such a utility twice it would not produce
an error but would *definitely* produce incorrect code.
e.g. int A[n] --> int A[n+1] --> int A[n+1+1]
2) No C programmer would find it easy to work with your original code
since it is written in something that is not quite C.
3) No non-C programmer would be able to work with your code since it
would be unlike any other language.
4) If you want a language that uses things like A[x,y] and allows arrays
to be indexed from something other than 0 there are plenty to choose
from.

Since you have not addressed any of the reasons people have stated why
what you are asking for is a bad idea we have absolutely no idea why you
are continuing with this unless it is that you are a troll.

BTW, there are plenty of things that I wish were different in C, but I
do what everyone else does and either use the language as is or use a
different language, I don't try to make C look like something different.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.

Frodo Baggins 09-30-2005 03:24 PM

Re: A[x][y][z]
 
> Let's combine the goodies from each language !

Reminds me of Perl ; best of sed,awk,sh,etc combined.
Regards,
Mohan S N



All times are GMT. The time now is 03:35 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.