delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/05/03/00:35:04

From: Neil Roy <royn AT usa DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Proper use of the & operator
Date: Sat, 02 May 1998 23:48:02 -0400
Organization: Sprint Canada Inc.
Lines: 51
Message-ID: <354BE8F2.90F18D8D@usa.net>
References: <1998042721215600 DOT RAA07160 AT ladder01 DOT news DOT aol DOT com>
Reply-To: royn AT usa DOT net
NNTP-Posting-Host: hme1-2.news.sprint.ca
Mime-Version: 1.0
Cache-Post-Path: michelob!unknown AT spc-isp-kgn-uas-01-8 DOT sprint DOT ca
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I am still rather new to C programming, but there is something I remembered from a
book on C programming that was describing pointers to variables and when it came to
the scanf() function the only type of variable you didn't use & with was a string
variable because it is a pointer to a character array variable (there are no
strings in C).  So as far as I can tell, you should be able to use

             memset(strbuf, 0, 13);

just fine, without the & (address of) operator because strbuf is already a
pointer.  If you see what I mean.

    As for other compilers having problems with that, they may have had problems if
you placed an & in front because it is a pointer and doesn't need an & (string
variables are really just pointers to character arrays).

     I hope this helped you.  If need be I can look up the chapter and quote you
what I read if I wasn't clear enough.

     Happy programming;
     Neil "NiteHackr" Roy


Fist1000 wrote:

> If I have an array, for example:
>
>     char strbuf[13];
>
> what does &strbuf, yield? I usually do the following to zero such an array:
>
>     memset(strbuf, 0, 13);
>
> or
>
>     memset(&strbuf[0], 0, 13);
>
> but i've recently noticed the following in someone else's code:
>
>     memset(&strbuf, 0, 13);
>
> I thought this was invalid, but it seems to compile. I'm no master of pointers
> or references, but that seems incorrect. I've been porting some code from DJGPP
> to Watcom, and in many cases in the Watcom code, it doesn't like &strbuf and
> will give me a bunch of bogus data. Anyone have any insight into this? Please
> reply by e-mail. Thanks.
>
> Later,
> Aen (fist1000 AT aol DOT com)



- Raw text -


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