Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!husc6!seismo!mcnc!rti-sel!dg_rtp!throopw From: throopw@dg_rtp.UUCP Newsgroups: comp.lang.c Subject: Re: arrays vs. pointers Message-ID: <1370@dg_rtp.UUCP> Date: Fri, 13-Mar-87 15:38:59 EST Article-I.D.: dg_rtp.1370 Posted: Fri Mar 13 15:38:59 1987 Date-Received: Sat, 14-Mar-87 09:08:24 EST References: <274@voodoo.UUCP> Lines: 63 > bill@voodoo.UUCP (Bill Sears) > One problem that I have had concerning arrays and pointers had to do with > declaring a char array in one module and accessing it as a char pointer > in another module. For example: Not surprising you have a "problem" with it, since it is illegal. Lint has this to say about the example you posted. main.c ============== (8) warning: main() returns random value to invocation environment ============== value type declared inconsistently Big_buf defs.c(1) :: main.c(7) > This only is a problem if you have the declaration > and the dereference in separate files. Well, let's see what lint has to say when everything is in one file: main.c ============== (5) redeclaration of Big_buf (10) warning: main() returns random value to invocation environment It's still a problem. Lint still complains. You mean you didn't lint it? Why not? > Anyone seen any compilers that handle the first example "properly". Since "proper handling" in this case is the production of an error message, and since no compiler I'm familiar with reads multiple source files, I'd have to say that no compiler I'm familiar with handles it properly. On the other hand, lint does handle it properly. What's that? You say you thought this example was legal? Why? You thought pointers and arrays were the same thing in C? Foolish earth creature! I recommend reading "The C Programming Language", by Kernighan and Ritchie. As near as I can tell, this book is a "classic" by Mark Twain's definition. By the way, why didn't you just do the obvious thing: decl.c: char Big_buf[512]; main.c: main() { extern char Big_buf[]; int i; for (i = 0; i < 512; i++) *(Big_buf + i) = 0; return( 0 ); } Lint doesn't complain about this at all. -- Classic: a book which people praise but don't read. --- Mark Twain -- Wayne Throop !mcnc!rti-sel!dg_rtp!throopw