How to Specify a NULL struct

The Apache API generally uses a NULL struct to mark the end of any array of struct's that it uses. There are many such struct's that a module writer has to create. For the C programmer a NULL struct can just be {NULL} but for a C++ programmer this does not pass strong typing muster.

When initializing an array of struct's in C++ each of the initializing structs must have complete data for all the members of the relevent struct type and each item must be of the correct type. Luckily NULL is automatically considered to be of the correct type for any pointer so the explicit casting can be somewhat minimized.

The example contains the NULL records for the most commonly used structs in Apache.


Source File

// Here is a valid type-safe NULL record for the command_rec struct.
static command_rec foomod_cmds[] =   {
    {NULL, NULL, NULL, 0, cmd_how(0), NULL}    

// And for handler_rec
static const handler_rec foomod_handlers[] = {
    { NULL, NULL }

External Documentation

The following is excerpted from Apache 1.3's http_config.h:

/* This structure records the existence of handlers in a module... */

typedef struct {
    const char *content_type;   /* MUST be all lower case */
    int (*handler) (request_rec *);
} handler_rec;

The following is excerpted from Apache 1.3's http_config.h:

typedef struct command_struct {
    const char *name;           /* Name of this command */
    const char *(*func) ();     /* Function invoked */
    void *cmd_data;             /* Extra data, for functions which
                                 * implement multiple commands...
    int req_override;           /* What overrides need to be allowed to
                                 * enable this command.
    enum cmd_how args_how;      /* What the command expects as arguments */

    const char *errmsg;         /* 'usage' message, in case of syntax errors */
} command_rec;

Zachary C. Miller
Last modified: Tue Sep 14 02:16:46 CDT 1999