Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c    |    Meh, in C you gotta define EVERYTHING    |    243,242 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 242,737 of 243,242    |
|    Andrey Tarasevich to Chris M. Thomasson    |
|    Re: function pointer question    |
|    03 Jan 26 13:01:07    |
   
   From: noone@noone.net   
      
   On Sat 1/3/2026 12:04 PM, Chris M. Thomasson wrote:   
    > struct object_prv_vtable {   
    > int (*fp_destroy) (void* const);   
    > };   
   And interesting piece of trivia about C function types and function type   
   compatibility rules is that:   
      
   1. Top-level qualifiers on function parameters are preserved as part of   
   function type. However, such top-level qualifiers are ignored when   
   determining function type compatibility.   
      
   2a. Pre-C17: Top-level qualifiers on function return type are preserved   
   as part of function type. They are NOT ignored when determining function   
   type compatibility, i.e. they have to match exactly for the types to be   
   compatible.   
      
   2b. Post-C17: Top-level qualifiers on function return type are not   
   included into the function type. (Function type compatibility rules   
   remain unchanged: they still formally require a match, but now it's moot.)   
      
   For example, the following intializations are valid   
      
    int foo(const int);   
    int bar(int);   
    ...   
    int (*pa)(int) = &foo;   
    int (*pb)(const int) = &bar;   
      
   Note: they function types do not match in this case, yet they are   
   compatible. And that's all that's needed.   
      
   Meanwhile, the following initializations are invalid in pre-C17 version   
   of the language   
      
    const int baz(void);   
    int qux(void);   
    ...   
    int (*pc)(void) = &baz;   
    const int (*pd)(void) = &qux;   
      
   They become valid in C17 and later.   
      
   (Interestingly enough, Clang keeps complaining about them even in   
   `-std=c17` mode.)   
      
   --   
   Best regards,   
   Andrey   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca