Mail Archives: djgpp/2001/03/27/02:46:53
On Tue, 27 Mar 2001 08:52:04 +0200 (IST), Eli Zaretskii
<eliz AT is DOT elta DOT co DOT il> wrote in comp.os.msdos.djgpp:
>
> On Tue, 27 Mar 2001, Jack Klein wrote:
>
> > > scanf("%s", &string);
> >
> > The line above is incorrect, the name of a character array like string
> > is always converted to a pointer to its first element when passed to a
> > function. Just "string" is the address of string[0]. &string is a
> > pointer to an array of characters, not a pointer to char. This just
> > happens to work on most compilers "by accident".
>
> It works, and not by accident. But you are right: it's bad C.
No, there is no requirement that a pointer to an array of chars has
the same representation as a pointer to char, just as there is no
requirement for pointer to any different scalar types to have the same
representation, with the exception of pointer to char and pointer to
void.
So it does work by accident.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
- Raw text -