NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » lcd streams - Can a 'stream be defined that has a scope across the entire program?

November 05, 2011
by JimFrederickson
JimFrederickson's Avatar

I am not really a "C" person, but I can do a few things.

I can use a 'stream' to send data to the LCD.

What I was wondering though...

Can a 'stream be defined to have a global scope for the program'?

The only way I have been able to get it to work is by 'defining a stream in each function that I use a stream to print in'...

I was wondering if I could just define 'lcd_stream' one time and reuse that?

Does it matter?

Thanks...

November 06, 2011
by rob_k
rob_k's Avatar

I am not a c expert, so take what I say with a grain of salt.

You could define the stream in a header file, and include that wherever you wanted it. If you have the header guards (i.e., the #ifdef something #define something #endif business), you can be guaranteed it will only be defined once, and also would be global wherever you include the header file.

Global streams are usually a bad idea, but I assume you are not doing any preemptive multitasking so it probably would be fine.

November 09, 2011
by JimFrederickson
JimFrederickson's Avatar

I just gave up on using the LCD as a 'Stream'...

I couldn't find a way that worked for me where a 'Stream' could be opened and used from within various functions as I needed.

I just created my own routines that could be called from the necessary functions without having to open a 'New Stream' or 'Sharing a Stream'.

It is, in the end, more efficient, as far as space usage goes, in any case.

Thanks though.

Post a Reply

Please log in to post a reply.

Did you know that NerdKits make a great parent/child activity? Learn more...