From: Jack Klein Newsgroups: comp.os.msdos.djgpp Subject: Re: is this a bug? Message-ID: <2tg0cts3iddc003gfs3q9mma4qj9droi1t@4ax.com> References: X-Newsreader: Forte Agent 1.8/32.548 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 31 Date: Tue, 27 Mar 2001 07:35:36 GMT NNTP-Posting-Host: 12.75.160.207 X-Complaints-To: abuse AT worldnet DOT att DOT net X-Trace: bgtnsc04-news.ops.worldnet.att.net 985678536 12.75.160.207 (Tue, 27 Mar 2001 07:35:36 GMT) NNTP-Posting-Date: Tue, 27 Mar 2001 07:35:36 GMT Organization: AT&T Worldnet To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com On Tue, 27 Mar 2001 08:52:04 +0200 (IST), Eli Zaretskii 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