Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2002-10

How to translate an Union from C to Pascal?

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

milimeter

Hello, every one

Does anybody know how to translate an Union in a C code to Pascal? Please see the following codes in C (from source of gedit 2.0.2):

struct _GeditUndoAction
{

	GeditUndoActionType action_type;
	union {
		GeditUndoInsertAction	insert;
		GeditUndoDeleteAction   delete;
	} action;
	gboolean mergeable;
	gint order_in_group;
};

I want to translate it to Pascal, but I don't know how to handle the union Action in it.

Thank you very much.
mili

Reply by email

Jonas Maebe
to milimeter
milimeter wrote 17 lines
struct _GeditUndoAction { GeditUndoActionType action_type; union { GeditUndoInsertAction insert; GeditUndoDeleteAction delete; } action; gboolean mergeable; gint order_in_group; }; I want to translate it to Pascal, but I don't know how to handle the union Action in it.

A union is the same as a variant record. Here's a possible translation:

type
   TAction = record
     case byte of
       1: (insert: GeditUndoInsertAction);
       2: (delete: GeditUndoDeleteAction);
   end;
   T_GeditUndoAction = record
     action_type: GeditUndoActionType;
     action: TAction;
     mergeable: gboolean;
     order_in_group: gint;
   end;

Jonas

Reply by email

Adam Naumowicz
to milimeter: Hello, every one Does anybody know how to translate an Union in a C code to Pascal?…
milimeter wrote
Does anybody know how to translate an Union in a C code to Pascal?

A 'case' variant of a record should be a good equivalent.

Adam Naumowicz

====================================================================== Department of Applied Logic fax. +48 (85) 745-7662 Institute of Computer Science tel. +48 (85) 745-7559 (office) University of Bialystok e-mail:
Sosnowa 64, 15-887 Bialystok, Poland http://math.uwb.edu.pl/~adamn/ ======================================================================

Reply by email