Using pointers to struct members as args to functions

In a well-known book on the C language, there is an example of an efficient method for using a struct member as an argument to a function. (I'm a C noob, but I believe the correct terminology might be: use call-by-reference instead of call-by-value.) The function is printf.

Anyway, here's a similar example, to illustrate the technique:

struct a *pp;

struct a b;
b.1 = c; 
b.2 = cc; 
b.3 = ccc; 
b.4 = cccc; 
}

struct a b, *pp;

pp = &b;

printf("b.1 is %s\n",(*pp).b.1);

This is easy enough to understand.

But how do we do this with structure members that are themselves pointers or functions?

Let's say I have a struct that resembles the one below. And I want to print the value of lg.

const struct kelly {
const char *cindy;
const char *juliette;
void (*anna)(const char *);
void (*jennifer)(void);
void (*rachel)(void);
void (*lg)(int);
char *(*christine)(const char *, char *);
} 

Just learn to keep in mind when you're using a pointer as a value and when you're using the value it points to. To print the value of lg, use:

/* `const' is useless here! */
struct kelly {
    /* ... */
    void (*lg)(int);
};

struct kelly kelly_smith;
printf("lg of kelly_smith = %p\n", kelly_smith.lg);

Edit: Unless kelly_smith is declared as a pointer, in which case use:

struct kelly *kelly_smith;
printf("lg of kelly_smith = %p\n", kelly_smith->lg);

/* Or, equivalently... */
printf("lg of kelly_smith = %p\n", (*kelly_smith).lg);

Struct member lg is a pointer to a function that takes an int and returns void...so i am not sure what you mean when you want to print its value. Value in lg will be address of the function it is pointing to and dereferencing it *lg is the same thing as calling that function..kind of like

void f(int);
int i;
struct kelly k;
k.lg=f;
printf("value in lg is %u\n", lg);   // which is the address of function f
*lg;   // same as calling f(i)

JohnGraham: Would const be useful if the struct was as follows?

const struct kelly {
/* ... */
void (*lg)(int);
} friends[] = {
/* ... */
};

Shamrock: Many thanks.

The "kelly" struct is based on real code that works well, but I (sloppily) took it out of a reasonably complex context, where the function being called by dereferencing "lg" varies based on the program name, whether input is from stdin/file, the command line arguments, sanity checks, etc.

To understand this code, there's a fair amount of indirection to resolve. The reward if I can figure it out is that it's a workable example of how to parse an above average number of command line variations.

Yes, (assuming you want all the elements of your array to be const) since that's qualifying the array. It seemed like you wanted to make a const type (which you could do with a typedef).

JG: Would you believe I also omitted a typdef that did just that? For the kelly example, I took the struct out of a context where I still don't fully understand the context. Hence the omissions.

Cheers for the helpful insights.