arrays vs. pointers

throopw at dg_rtp.UUCP throopw at dg_rtp.UUCP
Sat Mar 14 06:38:59 AEST 1987

> bill at 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.

    (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:

    (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:

        char Big_buf[512];
            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      <the-known-world>!mcnc!rti-sel!dg_rtp!throopw

More information about the Comp.lang.c mailing list