delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/07/02/07:40:31

X-Authentication-Warning: anthony.siemens.ebp.ii3.b-rail.be: ddemerre owned process doing -bs
Date: Mon, 2 Jul 2001 13:38:07 +0200 (CEST)
From: Dieter Demerre <ext DOT dieter DOT demerre AT siemens DOT be>
X-Sender: <ddemerre AT anthony DOT siemens DOT ebp DOT ii3 DOT b-rail DOT be>
To: <djgpp AT delorie DOT com>
Subject: Re: (No Subject)
In-Reply-To: <FONHIJOBJKKAFCAA@mailcity.com>
Message-ID: <Pine.LNX.4.30.0107021332480.13517-100000@anthony.siemens.ebp.ii3.b-rail.be>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Mon, 2 Jul 2001, poojitha s sajja wrote:

> Can anyone please tell me How can I pass a pointer of structure type,
> from say prog1.c to prog2.c

you make a .h header file defining the pointer as extern, which you then
include within your .c file thus making it accessable.

e.g.

within prog1.h
==============
typedef struct {
  int i;
  char* j;
} T_example_S;

typedef T_example_S* T_example_P;

extern T_example_P p;
/*-----------------------------------------*/
within prog1.c
==============
T_example_P p;

void function1(void)
{
  p->i = 12;
}
/*-----------------------------------------*/
within prog2.c
==============
#include "prog1.h"

void function2(void)
{
  switch (p->i)
  {
    case 12: p->j = "Function 1 was already called.\n"; break;
    default: p->j = "peulengaleis rules.\n"; break;
  }
}
/*-----------------------------------------*/

Good Luck !!!

-- Groetjes vanwege... Greetings from... --
-- Dieter Demerre  ***  ddemerre AT acm DOT org --
-- http://www.angelfire.com/de/ddemerre/ --

-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS/d- s+:++ a-()>-- C+ UH P++(+) L++ E W++ N+ o K? w o V
M PS+ PE- Y+ PGP+ t 5? X+ R+> tv+ b+ DI D G e+++ h+> r% z-
------END GEEK CODE BLOCK------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019