On Thu, Aug 11, 2005 at 02:08:58PM +0100, Paul wrote:
Coding styles can be an emotive subject (along the lines of which is better, vi or emacs). I for one find the GNU recommended style to be horrible, preferring the guidance found in Documentation/CodingStyle (from any kernel source) to be reasonable.
On Thursday 11 August 2005 13:25, Stuart Bailey wrote:
Yes, but as far as I can remember (and I may be verging on C++), you can have functions within a struct. Therefore, you could create an initialisation function, with well named parameters (with defaults), that will setup the struct for you. Although you will still have a long parameter list. Unfortunately, I can't remeber the syntax - and I can't find any of my C books to reference. But basically, a C++ class is essentially a structure whose members are by default private rather than public as in structures.
struct Foo{ public: Foo() {a=0; b=2; c=3; bar="idunno"};
int a; int b; int c; char bar[80]; }
However, this only works with C++, so one small trick I use is a macro defined in the same header as the struct definition..
typedef struct { double s, x, y, z; } PmRotation;
#define PmRotation_init {1, 0, 0, 0}
Both these examples show exactly what I'm trying to avoid, the separation into two different lists of the declarations of the variables and their initialisation. When there's a large number of variables it's very difficult to keep track of which initialisation value goes with which variable.