Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uunet!mcsun!hp4nl!philapd!ssp11!dolf From: dolf@idca.tds.PHILIPS.nl (Dolf Grunbauer) Newsgroups: comp.lang.c Subject: Re: Return value from a macro Keywords: macro linked list Message-ID: <634@ssp11.idca.tds.philips.nl> Date: 1 Feb 90 09:46:03 GMT References: <960@pyrite4.UUCP> <7727@pt.cs.cmu.edu> Organization: Philips Telecommunication and Data Systems, The Netherlands Lines: 23 In article <7727@pt.cs.cmu.edu> mwm@a.gp.cs.cmu.edu (Mark Maimone) writes: ]In article <960@pyrite4.UUCP> Larry Baltz writes: ]>The problem I'm having is trying to have the macro return a value of the ]>deleted link. ] You can just use the comma operator to return a value (the value of ]a comma-expression is the last item in the list). Here's one solution: ] ]#define delete_head(head) ((header->next == header) ? NULL : \ ] (dh_temp = (head)->next, dh_temp->next->prev = (head), \ ] (head)->next = dh_temp->next, dh_temp)) ] ]static LINK dh_temp; Oke, but note that the solution of Mark doesn't work when the code is supposed to be shared by other processes at the same time. E.g. in a kernel or a shared library there probably will only be one dh_temp for all processes thus (due to scheduling cq process switching) it is likely that these processes ruin the value of dh_temp, creating very hard to trace errors/bugs/panics. -- Dolf Grunbauer Tel: +31 55 433233 Internet dolf@idca.tds.philips.nl Philips Telecommunication and Data Systems UUCP ....!mcvax!philapd!dolf Dept. SSP, P.O. Box 245, 7300 AE Apeldoorn, The Netherlands n n n It's a pity my .signature is too small to show you my solution of a + b = c