home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!utcsri!torn!mcshub!maccs!cs4gp6au
- From: cs4gp6au@maccs.mcmaster.ca (Lockie RJ)
- Subject: c and modula2
- Message-ID: <1993Jan25.184916.23553@mcshub.dcss.mcmaster.ca>
- Sender: cs4gp6au@maccs.dcss.mcmaster.ca
- Nntp-Posting-Host: maccs.dcss.mcmaster.ca
- Organization: Department of Computer Science, McMaster University
- Date: Mon, 25 Jan 1993 18:49:16 GMT
- Lines: 33
-
- Ok. I have a question about the difference between C and
- Modula-2.
- Here's some C code (correct I hope):
- struct ex {char word[10};
- struct ex test[10];
- struct ex *p;
- p = &test[0]; /* or p = test */
- p ++;
- /* p now points to test[1] according to K&R2 pg. 98 */
-
- Here's some Modula-2 code:
- TYPE ex = ARRAY[0..10] OF CHAR;
- VAR test : ARRAY[0..10] OF ex;
- p : POINTER TO ex;
- BEGIN
- p = ADR(test[0]);
- INC( p );
- (* p now points to test[0][1] *)
-
- So, if the above code is correct, the question I have is why does
- incrementing a pointer in C point to the next element in the array?
- while in Modula-2 it doesn't (the pointer needs to be incremented
- by the size of the array element).
- How does C do that? Is it the compiler? In Modula-2, to increment to
- the next element in the array it would require:
- INC( p, SIZE(ex) );
-
- So is this code correct? And how is this feature of C implemented?
-
- Bob Lockie: cs4gp6au@maccs.dcss.mcmaster.ca
-
-
-
-