🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #3635

Re: Wishful thinking: return-parameter

#3635
From: Peter Holzer
Date: Thu, 03 Aug 1995 09:46
38 lines
2058 bytes
mfx@cs.tu-berlin.de (Markus Freericks) writes:

>In article <3vl6b2$dne@solutions.solon.com> seebs@solutions.solon.com (Peter Seebach) writes:
>> >- what if you _want_ one or all results to be undefined?
>> 
>> Give a real-world example, and I'll worry about it.

>A function that determines the intersection between two line segments,
>determined by four float arguments (two points) each, returning an enum
>flag (no intersection / one point intersection / line segment intersection)
>and four float results, of which either none, two, or all four are
>defined.

You cannot return multiple values in C anyway, so this is moot. You
can return a structure and are free to initialize only some of its
fields. And you are also free to change or not change locations to
which pointers are passed to the function. Both possibilities cover
your example:

typedef enum {NONE; POINT, LINE} intdesc_t;
typedef struct { 
    intdesc_t type;
    float x1, y1, x2, y2;
} intersect_t;

intersect_t intersection1 (float l1x1, float l1y1, float l1x2, float l1y2,
			  float l2x1, float l2y1, float l2x2, float l2y2);

intdesct_t intersection2 (float l1x1, float l1y1, float l1x2, float l1y2,
			  float l2x1, float l2y1, float l2x2, float l2y2,
			  float *ix1, float *iy1, float *ix2, float *iy2);

	hp
--
   _  | Peter Holzer | Systemadministrator WSR | hjp@wsr.ac.at
|_|_) |-------------------------------------------------------
| |   |  ...and it's finished!  It only has to be written.
__/   |         -- Karl Lehenbauer
Technical Details
Message-ID: <3vq5so$8td@wsrcom.wsr.ac.at>
Path: arc1-ca.pugleaf.net!wsrcom.wsr.ac.at!wsrdb!hjp
References: <3ver2u$8bk@caip.rutgers.edu> <3viv5u$bkv@news.cs.tu-berlin.de> <3vjlmk$8co@caip.rutgers.edu> <3vkvmm$rtt@news.cs.tu-berlin.de> <3vl6b2$dne@solutions.solon.com> <3vnqah$1ev@news.cs.tu-berlin.de>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!wsrcom.wsr.ac.at!wsrdb!hjp
From: hjp@wsrdb.wsr.ac.at (Peter Holzer)
Newsgroups: comp.std.c
Subject: Re: Wishful thinking: return-parameter
Date: 3 Aug 1995 09:46:00 GMT
Organization: WSR, Vienna, Austria
Message-ID: <3vq5so$8td@wsrcom.wsr.ac.at>
References: <3ver2u$8bk@caip.rutgers.edu> <3viv5u$bkv@news.cs.tu-berlin.de>  <3vjlmk$8co@caip.rutgers.edu> <3vkvmm$rtt@news.cs.tu-berlin.de>  <3vl6b2$dne@solutions.solon.com> <3vnqah$1ev@news.cs.tu-berlin.de>
NNTP-Posting-Host: wsrdb.wsr.ac.at