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 function argument

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



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

stream as function argument
PostPosted: Thu Jun 28, 2007 4:01 pm     Reply with quote

Does CCS permit to pass a stream (or a pointer to a stream) to a function as an argument? Like this for example
Code:

#use rs232(..., stream=one232)
#use rs232(..., stream=two232)

int8
check_send(stream m, // stream to send to
 char* s) // null terminated string to send
{
 fprintf(m, s);
 return check_sum(s);
}

// calling code
void main()
{
 //...
 iChkSum = check_send(one232, "hello");
 //...
 iChkSum = check_send(two232, "world");
 //...
}


Unfortunately, I couldn't make it work?
_________________
Read the label, before opening a can of worms.
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: stream as function argument
PostPosted: Thu Jun 28, 2007 10:17 pm     Reply with quote

kender wrote:
Does CCS permit to pass a stream (or a pointer to a stream) to a function as an argument? Like this for example
Code:

#use rs232(..., stream=one232)
#use rs232(..., stream=two232)

int8
check_send(stream m, // stream to send to
 char* s) // null terminated string to send
{
 fprintf(m, s);
 return check_sum(s);
}

// calling code
void main()
{
 //...
 iChkSum = check_send(one232, "hello");
 //...
 iChkSum = check_send(two232, "world");
 //...
}


Unfortunately, I couldn't make it work?


I think you could probably write your own using a pointer to the hardware shift buffers. CCS does not support this because it can not work with a software serial port. At the end of the day I think it would be better (easier) to just pass a bit in the function call to switch between ports.
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

Re: stream as function argument
PostPosted: Thu Jun 28, 2007 10:21 pm     Reply with quote

Neutone wrote:
CCS does not support this because it can not work with a software serial port.

But somehow fputc() and fprintf() take a stream as an argument.
_________________
Read the label, before opening a can of worms.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 28, 2007 10:54 pm     Reply with quote

Quote:

But somehow fputc() and fprintf() take a stream as an argument.

They do, but it's only used at compile-time. If you look at the compiled
code in the .LST file, there is no code inserted which checks a variable
to see which stream to use. The decision is made entirely at compile-
time and fputc() is hard-coded to use the selected stream at that time.
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