www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/04/29/06:43:00

From: jstacey AT plato DOT wadham DOT ox DOT ac DOT uk (J-P)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Weird : Segmentation fault on fwrite :(
Date: 29 Apr 2000 11:54:37 +0100
Organization: Wadham College Oxford
Lines: 29
Message-ID: <8eef1d$ai7$1@plato.wadham.ox.ac.uk>
References: <956963090 DOT 719428 AT romulus DOT infonie DOT fr> <20000429101940 DOT A22474 AT chance DOT cz> <957001855 DOT 943830 AT romulus DOT infonie DOT fr>
NNTP-Posting-Host: plato.wadham.ox.ac.uk
X-Trace: news.ox.ac.uk 957005678 10799 163.1.164.74 (29 Apr 2000 10:54:38 GMT)
X-Complaints-To: newsmaster AT ox DOT ac DOT uk
NNTP-Posting-Date: 29 Apr 2000 10:54:38 GMT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

In article <957001855 DOT 943830 AT romulus DOT infonie DOT fr>,
HPMAN <mwa DOT p AT infonie DOT fr> wrote:
>Isn't the '&' supposed to be implicit with arrays ?
>
>Always used an '&' with arrays and worked fine...

This misunderstanding suggests you might want to read more about C than
about DJGPP:

	If char arrayname[80] is an array of 80 char,
	 . arrayname is (equivalent to) a pointer to the first char
	 . &arrayname is a pointer to a pointer to the first char

So in your example:

>fwrite(TestBuff,sizeof(char),32,output);

is correct, as TestBuff is pointer-to-char, but:

>fwrite(&TestBuff,sizeof(char),32,output); 

is wrong, because &TestBuff is a pointer-to-pointer-to-char.

This is fundamental C programming. Have a look at Kernighan & Ritchie, or
possibly the C FAQ.

J-P
-- 
innowacyjną architekturą firmy NetManage związanąz

- Raw text -


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