passing data to functions in other units

From: Kris Leech (krisleech_at_email.com)
Date: 08/31/04


Date: Tue, 31 Aug 2004 16:12:24 +0000 (UTC)

Hi ya, The program i am writing has got very long and i want to break it
up in to units to make it more readable/maintainable.

My main unit will then call functions in other units. This is fine
expect that currently my main unit does not pass variables to the
functions it calls, instead they all work on a global variable.

Once my functions are in other units that global variable is no longer
available. What is the best way to get the variable to the functions in
the other units.

I assume i can either pass the whole variable to the functions (which
may be slow?) or pass a pointer to the global variable??

The global variable i have is a static array of bytes.

Thanks for any help or pointers ;)

Kris.



Relevant Pages

  • Re: Memory management and allocation
    ... > As I'm writing a piece of code that basically acts as a server and ... > memory management is a topic that is quite crucial. ... Or can I just allocate the variable ... Nor is it usually necessary to set the pointer to ...
    (comp.lang.c)
  • Re: FIFO File writing
    ... > To write a new record, read the 0th, form the pointer, seek there ... > binary operations, i.e. this is a binary file. ... > The file is vulnerable between writing the new record and writing ... > by first writing an invalid marker to the index record, ...
    (comp.programming)
  • Re: gdb not catching out-of-bounds pointer
    ... is also not defined by the C-standard, IOW: writing code in anything ... provided the library writer knows what the compiler writer guarantees ... etc.) that don't point into the same array than I would about the sort ... of pointer aliasing issue that started this sub-thread. ...
    (comp.unix.programmer)
  • Re: FIFO File writing
    ... how to implement a file logging system? ... To write a new record, read the 0th, form the pointer, seek there ... The file is vulnerable between writing the new record and writing ... by first writing an invalid marker to the index record, ...
    (comp.programming)
  • Re: Answer needed
    ... as the last element of the array the data was written outside the allotted ... I re-wrote the offending function with proper checks of the pointer value. ... > including what you expect writing code to see what the result will be ...
    (alt.comp.lang.learn.c-cpp)