Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: function pointer question Date: Fri, 02 Jan 2026 12:07:02 -0800 Organization: None to speak of Lines: 120 Message-ID: <87v7hju6c9.fsf@example.invalid> References: <10j7rs6$7c9e$1@dont-email.me> <20260102091518.226@kylheku.com> <10j96mn$jrsp$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Fri, 02 Jan 2026 20:07:03 +0000 (UTC) Injection-Info: dont-email.me; posting-host="0c5ef296c1f282275d44508e0b1eb011"; logging-data="698381"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ifu9fJC6iV3sjBH++eniQ" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:bU9MOpfwbE8B0rKsxtpf2hFErVc= sha1:72KELKFrhYlG5OcwxDM9KgiPlNQ= Xref: csiph.com comp.lang.c:396088 Michael Sanders writes: > On Fri, 2 Jan 2026 17:48:16 -0000 (UTC), Kaz Kylheku wrote: >> On 2026-01-02, Michael Sanders wrote: >>> B: because every function must have a return type >>> *including function pointers*? >> >> What it is you think type is, in the context of C? >> >> Does type survive into run-time? >> >> If a function pointer is missing type information about return type, and >> that function pointer is needed for expressing a function call, where >> does the compiler get the type from? > > Its void that's throwing me Kaz. I'm not sure what to think when > it comes to void pointers. There were no void pointers in the original code. There were function pointers to functions that return void. > A void pointer (the pointer itself) is not of the type > it points to no? Its typeless & unknown at compile time No pointer is of the type it points to. `int` and `int*` are distinct types. (The latter is "derived" from the former.) > A 'normal' pointer in C is a variable that stores the address > of another variable. Yes, if by "pointer" you mean "pointer object". The standard also uses the word "pointer" for a *value* of pointer type, for example the result of a call to malloc(). (The word "variable" is tricky, and the standard rarely uses it. "Object" is less ambiguous.) > And *is of the type it points to*... No. > char str[] = "learning publicly is a humbling experience."; > char *ptr = str; And now you're introducing array-to-pointer conversion, a can of worms that I suggest needn't be opened at this time. A simpler example: char c = 'l'; char *ptr = &c; > Then void enters stage left... > > void *genericPointer; > > It can point to an integer, a character, a structure, or any other type. > > void *genericPointer = &intValue; "intObject" would be a better name. An object (variable you like) is not a value; it holds a value. > void *genericPointer = str[]; That's a syntax error, but it's ok if you drop the "[]". void* is a distinct type. Unlike (most) other object pointer types, it can't be dereferenced, because it doesn't specify a directly usable type for the object it points to. Given: int n = 42; int *ip = &n; void *vp = &n; ip points to n. vp, in a sense, does not, but converting vp from void* to int* yields a pointer value that does point to n. A void* holds something you can think of as a raw untyped address. It doesn't point to anything, but converting it to foo* gives you a pointer to an object of type foo. > And it seems to survive a lack of type at compile time. > Man I'm confused on this. I mean I get void is flexible, > but 'void' is not void in any sense... its like a mask in some > way (I'm groping for a definition) I need to study void more. "void" is an incomplete type that cannot be completed. "void*" is a pointer type with some special characteristics. First, a value of any object pointer type can be converted to void* and back again, yielding the original pointer value. This is not guaranteed for (most) other pointer types. For example, converting a char* value to int* can lose information. (On most real-world systems, all object pointers, and often all function pointers as well, have the same representation, but the standard doesn't guarantee this.) Second, conversions between void* and other object pointer types are often performed implicitly. You can have an object pointer on one side of an assignment and a void* pointer on the other side. On some (exotic) systems, this conversion might do something more than just copying the representation. The character pointer types char*, signed char*, and unsigned char* share the first characteristic, but not the second. (In very early (pre-ANSI) C, char* was commonly used as a generic pointer type before void and void* were introduced.) Every pointer value, object, or expression has a well defined type, specifically a pointer type. That type specifies the type of the object it points to -- unless the pointer is of type void*. (Or it can point to a function; object pointers and function pointers are distinct.) The comp.lang.c FAQ has some good information, though some of it is a bit dated. Section 4 covers pointers, and section 6 covers arrays and pointers. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */