2008-01-24 06:43 PM
2011-05-17 12:49 AM
Hi,
I use the KEIL Realview MDK-ARM I want to define a functionpointer in the __FILE struct (stdio.h). By changing this functionpointer in my mainprogram I can redirect stdout to some device. To do this I changed the file retarget.c to following#include
extern ''C'' {
struct __FILE {
int handle;
int *(*stdoutProc)(int ch); //THIS IS THE FUNCTIONPOINTER I CREATED
};
FILE __stdout;
FILE __stdin;
InitStdOut(int *MyStdOut(int Ch)) {
__stdout.stdoutProc = MyStdOut;
}
int fputc (int ch, FILE *f) {
__stdout.stdoutProc(ch);
return(ch);
}
} //extern C
I did not test the code, so maybe the code doesn't do the thing I want to do, but however I can compile it without errors ! When I rename all the files to *.cpp, to use the compilers C++ extentions, I have the error (at the line FILE __stdout;) error #70: incomplete type is not allowed How can I add a functionpointer to the __FILE struct in C++ environment ???? Thank you !
2011-05-17 12:49 AM
You should not modify the struct. To redirect stdout (or stdin, stderr) the standard way is
console = freopen(''\MYLOGFILE.TXT'',''r+'',stdout); // ''r+'' means read/write assuming you have already written the low level drivers for your file system or IO stream.2011-05-17 12:49 AM
Thanks for response !
I think its better to write my own printf function. Luc