CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Stream as a parameter in a function

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Eastfield
Guest







Stream as a parameter in a function
PostPosted: Fri Aug 08, 2008 7:17 am     Reply with quote

hi all,

i am wondering how to use a stream as a parameter ?
i would like to do something like this :

void debug(stream _stream)
{
fprintf(_stream,"in this stream %?",stream);
}


thanks.
gribas



Joined: 21 Feb 2008
Posts: 21

View user's profile Send private message

PostPosted: Wed Aug 13, 2008 7:48 am     Reply with quote

I don't think that's possible. The compiler expects a constant for the first parameter of fprintf();

this works, but it's kinda useless:
Code:

#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=SERIAL)
void main() {
   const int stream = SERIAL;
   fprintf(stream,"test");
}


What about defining a debug stream? Like this:
Code:

#device PASS_STRINGS=IN_RAM

#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=SERIAL)
#define DEBUG_STREAM SERIAL

void debug(char* msg) {
   fprintf(DEBUG_STREAM,"%s",msg);
}

void main() {
   debug("test");
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group