delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/03/27/02:46:53

From: Jack Klein <jackklein AT spamcop DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: is this a bug?
Message-ID: <2tg0cts3iddc003gfs3q9mma4qj9droi1t@4ax.com>
References: <amb0ct41pn1s6rndo0bg9k5e2uif2e89jv AT 4ax DOT com> <Pine DOT SUN DOT 3 DOT 91 DOT 1010327085011 DOT 19916B-100000 AT is>
X-Newsreader: Forte Agent 1.8/32.548
MIME-Version: 1.0
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
<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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019