View previous topic :: View next topic |
Author |
Message |
bennyboos
Joined: 17 Nov 2005 Posts: 30 Location: Chester UK
|
STDOUT redirection |
Posted: Tue Oct 20, 2009 9:37 am |
|
|
Is there are way to redefine the default STDOUT to use my own choice of comms? As far as I can tell the compiler associates STDOUT with the last #use statement. Whilst I realise the ease of using #use RS232 functionality I am wondering if I can avoid it as I am trying to use generic code (for compatability with HiTech compilers) wherever possible, i.e. not use #use RS232.
I had hoped it was as as simple as just defining my own putc() and getc() routines which the compiler would then use for printf etc? However, when I try doing this (& deliberately miss out the #use RS232) the compiler gives errors, suggesting I might need a #use RS232 statement.
I realise there is another method & that is to use printf(fname, cstring ...) where I define my own fname, but again, this is rather non-standard.
What I had hoped for was just a means to redirect/define STDOUT to suit my own needs so that printf would default to that?
Any ideas ? |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Tue Oct 20, 2009 1:37 pm |
|
|
As far as I see, there's no other way than using the CCS proprietary printf() syntax. STDOUT respectively putchar() is a special compiler built-in stream/function, that can't be redefined.
To achieve compatibility with other compilers, preprocessor macros are required. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Oct 20, 2009 2:07 pm |
|
|
You could put #pragma in front of the #use rs232() statement. Then
only CCS would use it. Other compilers would presumably ignore it.
Code: |
#pragma use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
|
|
|
|
|