delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/12/18/15:15:15

From: Hans-Bernhard Broeker <broeker AT physik DOT rwth-aachen DOT de>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: pointer to functions - Warning error
Date: 18 Dec 2000 19:45:39 GMT
Organization: Aachen University of Technology (RWTH)
Lines: 37
Message-ID: <91lph3$7kp$1@nets3.rz.RWTH-Aachen.DE>
References: <3a3e5883 DOT 8164479 AT news DOT connectnet DOT com> <3a3e6258 DOT 10681619 AT news DOT connectnet DOT com>
NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de
X-Trace: nets3.rz.RWTH-Aachen.DE 977168739 7833 137.226.32.75 (18 Dec 2000 19:45:39 GMT)
X-Complaints-To: abuse AT rwth-aachen DOT de
NNTP-Posting-Date: 18 Dec 2000 19:45:39 GMT
Originator: broeker@
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

John Vasquez <jvasquez AT getntds DOT spam DOT com> wrote:
> Found the fix. 

No. You found an ugly workaround, IMHO.

> If I do the following in the structure, The error disappeared.

> int Myfunct(int x, void *adr);
> typedef struct _MyStruct{
> 	int (*funct)();	//don't include the parameter list
> }MyStruct;

That's bad coding practice. You should, by all means, leave the
parameter types in the function pointer typed element of your
structure.  Your declaration makes proper type checking by the
compiler impossible. In particular, it now won't warn even if you
assign to the pointer a function taking a char[30] and a double as it
arguments.

You may want to make things easier by using a typedef for the function
pointer type:

typedef int (*MyFunctPtr) (int, void*);

And then declare

MyFunctPtr Myfunct;
typedef struct {
	MyFunctPtr funct;
} MyStruct;

The typedef may also make your program work. In C, it can sometimes make
a difference wether you declare a same-looking type twice, or only once.

-- 
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.

- Raw text -


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