X-Authentication-Warning: delorie.com: mail set sender to geda-help-bounces using -f X-Recipient: geda-help AT delorie DOT com X-Mailer: exmh version 2.7.2 01/07/2005 (debian 1:2.7.2-18) with nmh-1.3 X-Exmh-Isig-CompType: repl X-Exmh-Isig-Folder: inbox To: geda-help AT delorie DOT com Subject: Re: [geda-help] Help, how can I help? In-reply-to: <20120123205725.GA15392@malakian.lan> References: <4F1A1196 DOT 20100 AT gmail DOT com> <201201210150 DOT q0L1o04r012622 AT envy DOT delorie DOT com> <4F1C643E DOT 7080503 AT gmail DOT com> <20120122234306 DOT GB13485 AT malakian DOT lan> <20120123121355 DOT 0d3ea4bc AT svelte> <20120123205725 DOT GA15392 AT malakian DOT lan> Comments: In-reply-to Andrew Poelstra message dated "Mon, 23 Jan 2012 12:57:25 -0800." Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Message-Id: <20120123233338.98CDD820B35D@turkos.aspodata.se> Date: Tue, 24 Jan 2012 00:33:38 +0100 (CET) From: karl AT aspodata DOT se (Karl Hammar) X-Virus-Scanned: ClamAV using ClamSMTP Reply-To: geda-help AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: geda-help AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk Andrew Poelstra: > On Mon, Jan 23, 2012 at 12:13:55PM -0800, Colin D Bennett wrote: > > On Sun, 22 Jan 2012 15:43:06 -0800 > > Andrew Poelstra wrote: > > > > > Function pointers may not be casted to function pointers of > > > different types. (This is very irritating, but it's what the > > > standard says.) > > > > I don't see how it's irritating. It's just the only sane thing to > > do. How is a function pointer usefull unless you know the argument > > types? > > > > Because a lot of times you have unnecessary arguments -- i.e., suppose > you had an object that looked like > > typedef struct stream_t { > /* some public data */ > int (*open) (struct stream_t *, int mode); > /* some other functions */ > } stream_t; ... If you want variable length argument list, why don't you use a variable length argument list? $ cat a.c #include #include typedef struct stream_t { /* some public data */ int (*open) (struct stream_t *, ...); /* some other functions */ } stream_t; int f(struct stream_t *this, ...); int g(struct stream_t *that, ...); int main(void) { stream_t a; a.open = f; a.open = g; f(&a); g(&a, 10); return 0; } int f(struct stream_t *this, ...) { printf("hello f\n"); return 0; } int g(struct stream_t *that, ...) { va_list ap; int mode; va_start(ap, that); mode = va_arg(ap, int); va_start(ap, that); printf("mode %d\n", mode); return 0; } $ gcc a.c $ ./a.out hello f mode 10 $ /// Since you pass a struct to the open(), why don't you just put the "int mode" into the struct: typedef struct stream_t { /* some public data */ int (*open) (struct stream_t *); int mode; /* some other functions */ } stream_t; then the open who needs it can get it from the struct. Regards, /Karl Hammar ----------------------------------------------------------------------- Aspö Data Lilla Aspö 148 S-742 94 Östhammar Sweden +46 173 140 57