🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #49792

Is this correct?

#49792
From: Lele Gaifax
Date: Fri, 10 Dec 1993 11:22
48 lines
1973 bytes
Situation:

in point.h I have

struct point
{
  int x;
  int y;
};

/* This macro should return a pointer to an initialized
 * struct point. I use it to generate inline points to be passed
 * as argument. If some space gets alloced, I would like it freed
 * automatically... */

#define POINT(_x,_y) ({struct point _p = {_x,_y}; &_p;})

in point.c I have

move_to_point (const struct point * const pp)
{
  /* some code to move to point */
}

Ok. point.c defines other functions that accept a pointer to a
struct point as the first argument. The question is about the macro POINT():
is it correct to use it like
	...
	move_to_point (POINT(45,34));
	...
??. Please note that *it does work*, but I guess it is not a correct use
of this GCC feature. I tried to use alloca to setup such a macro:

#define POINT(_x,_y) ({struct point * _pp = alloca(sizeof (struct point)); \
		       *_pp = (struct point){_x,_y}; \
		       _pp;})

Alloca gets some memory from the stack, and frees it when the function exits... 
or when the block ends?

Answers? Is there a way to safely implement this macro?
Thanx a lot,
lele.

--
Lele Gaifax - lele@itnsg1.science.unitn.it
..calling Emacs convenient, of course, is like calling oxygen useful
					Rens Troost
Technical Details
Message-ID: <lele.755522550@itnsg1>
Path: arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!howland.reston.ans.net!math.ohio-state.edu!caen!batcomputer!ghost.dsi.unimi.it!itnnext4!itnsg1!lele

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,877e47fd4e8cdb51,start
X-Google-Attributes: gid11318c,public
X-Google-ArrivalTime: 1993-12-10 17:26:08 PST
Newsgroups: gnu.gcc.help
Path: arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!howland.reston.ans.net!math.ohio-state.edu!caen!batcomputer!ghost.dsi.unimi.it!itnnext4!itnsg1!lele
From: lele@itnsg1.cineca.it (Lele Gaifax)
Subject: Is this correct?
Message-ID: <lele.755522550@itnsg1>
Sender: news@itnnext4.lii.unitn.it (Network news administrator)
Nntp-Posting-Host: itnsg1.science.unitn.it
Organization: Dipartimento di Informatica e Studi Aziendali, Universita' di Trento
Date: Fri, 10 Dec 1993 11:22:30 GMT
Lines: 48