V
V.Ch.
In near future I can face a prospect of writing some stuff in C. Being a
C++ programmer, I've got practically no experience in C. I'd be obliged
if someone could answer the following questions (from specific to more
general):
1. Having looked though some C sources I was horrified by the number of
macros. E.g., what could be the purpose of using this:
#define CFG_REF(c, f) ((c) -> f)
#define SERVER_ADDRESS(c) CFG_REF (c, server_address)
From the point of view of C++ coding, this would seem quite idiotic
(why not use -> operator directly?!). But I've got reasons to believe
that the guy who wrote this is a good C coder.
2. If you were to write some program that can potentially be compiled on
a number of platforms by different compilers, how would you declare
automatic variables? Does it pay of to be extra conservative and don't
assume that every compiler now supports C99 with respect to declaring
variables wherever you want? Personally, I find it not only tiresome,
but actually very bad to declare all the variables at the beginning of a
block. But then again, I am not a C programmer. Is there any consensus
here?
3. What are the ways to structure large programs? I am falling back to
C++ again, thinking about object-oriented programming in C (something
like fopen, fread/fwrite and fclose) and emulating VTBL interfaces with
vectors of function pointers. Any other aproaches here? Any
links/tutorials would be very welcome.
4. Any other links and suggestions that would be useful for a C++
programmer that has to write in C.
C++ programmer, I've got practically no experience in C. I'd be obliged
if someone could answer the following questions (from specific to more
general):
1. Having looked though some C sources I was horrified by the number of
macros. E.g., what could be the purpose of using this:
#define CFG_REF(c, f) ((c) -> f)
#define SERVER_ADDRESS(c) CFG_REF (c, server_address)
From the point of view of C++ coding, this would seem quite idiotic
(why not use -> operator directly?!). But I've got reasons to believe
that the guy who wrote this is a good C coder.
2. If you were to write some program that can potentially be compiled on
a number of platforms by different compilers, how would you declare
automatic variables? Does it pay of to be extra conservative and don't
assume that every compiler now supports C99 with respect to declaring
variables wherever you want? Personally, I find it not only tiresome,
but actually very bad to declare all the variables at the beginning of a
block. But then again, I am not a C programmer. Is there any consensus
here?
3. What are the ways to structure large programs? I am falling back to
C++ again, thinking about object-oriented programming in C (something
like fopen, fread/fwrite and fclose) and emulating VTBL interfaces with
vectors of function pointers. Any other aproaches here? Any
links/tutorials would be very welcome.
4. Any other links and suggestions that would be useful for a C++
programmer that has to write in C.