Return value from a macro
Dolf Grunbauer
dolf at idca.tds.PHILIPS.nl
Thu Feb 1 20:46:03 AEST 1990
In article <7727 at pt.cs.cmu.edu> mwm at a.gp.cs.cmu.edu (Mark Maimone) writes:
]In article <960 at 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 at 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
More information about the Comp.lang.c
mailing list