I’m working on some straight C code that will be compiled in as part of a larger project. I hacked up what I thought to be decent enough code that compiled and worked fine on it’s own. When I inserted this into the larger application, though, the compiler (VC++) choked. I think I’m mixing C++ and C when all I really want to C to fit into the rest of the application. My C/C++ skills, I’m afraid, are rusty.
My code is simple enough. It is the start of serial port communications for the NT environment. Optimally, I would want a single C file containing my functions (one to initialize the serial port, one to read from it, one to write from it - I’ve already coded these functions - see links below). I would open the serial port once and then be able to call the write and read functions anywhere else in the app using the open handle.
Compiling my c, h and another file to call the functions into a console app works great. Inserting this into the larger application chokes with the following:
c:\src\serial_nt.h(1) : error C2061: syntax error : identifier 'SerialInit'
c:\src\serial_nt.h(1) : error C2059: syntax error : ';'
c:\src\serial_nt.h(1) : error C2059: syntax error : 'type'
c:\src\serial_nt.h(3) : error C2143: syntax error : missing ')' before '*'
c:\src\serial_nt.h(3) : error C2143: syntax error : missing '{' before '*'
c:\src\serial_nt.h(3) : error C2059: syntax error : ')'
c:\src\serial_nt.h(3) : error C2059: syntax error : ';'
c:\src\serial_nt.h(5) : error C2143: syntax error : missing ')' before '*'
c:\src\serial_nt.h(5) : error C2143: syntax error : missing '{' before '*'
c:\src\serial_nt.h(5) : error C2059: syntax error : ','
c:\src\serial_nt.h(5) : error C2059: syntax error : ')'
c:\src\serial_nt.h(7) : error C2143: syntax error : missing ')' before '*'
c:\src\serial_nt.h(7) : error C2143: syntax error : missing '{' before '*'
c:\src\serial_nt.h(7) : error C2059: syntax error : ')'
c:\src\serial_nt.h(7) : error C2059: syntax error : ';'
c:\src\serial_nt.h(9) : error C2143: syntax error : missing ')' before '*'
c:\src\serial_nt.h(9) : error C2143: syntax error : missing '{' before '*'
c:\src\serial_nt.h(9) : error C2059: syntax error : ','
c:\src\serial_nt.h(9) : error C2059: syntax error : ')'
c:\src\instr_io.c(576) : warning C4013: 'SerialInit' undefined; assuming extern returning int
c:\src\instr_io.c(578) : warning C4013: 'SerialPuts' undefined; assuming extern returning int
If anyone is still with me, my source files are here (the main is just for the console test app):
http://larsen.is-a-geek.com/serial_nt.c
http://larsen.is-a-geek.com/serial_nt.h
http://larsen.is-a-geek.com/serial_nt_main.c
I’m really curious why the compiler is dying on the header file? Am I mixing C/C++? Also, what is the best way to organize this code? Would i need my handle to the serial port connection to be global? I know that my reading will have to occur in a whole seperate thread, but I’ll cross that bridge when I come to it.
Thanks,
LarsenMTL