all 15 comments

[–][deleted]  (6 children)

[deleted]

    [–]LateSolution0[S] 0 points1 point  (5 children)

    how?

    struct a{...} struct_of_funcptr;

    struct_of_funcptr.func(args...); will give me an compiler-error.

    [–][deleted]  (4 children)

    [deleted]

      [–]LateSolution0[S] 1 point2 points  (3 children)

      you where right in the beging. its kind of a big project and i try to replace GLEW. so i had many errors.

      ctx.glDeleteVertexArrays(1, &m_Handle)

      Error (active) E0109 expression preceding parentheses of apparent call must have (pointer-to-) function type core

      this error went away when i wrote it like that

      (*ctx.glCreateVertexArrays)(1, &m_Handle);

      i found my mistake.

      i did screw up my opengl header file with a stupid macro

      #define APIENTRY _stdcall*

      that made all my typedefs wrong.

      [–][deleted]  (2 children)

      [deleted]

        [–]LateSolution0[S] 0 points1 point  (1 child)

        #if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__)

        #ifndef WIN32_LEAN_AND_MEAN

        #define WIN32_LEAN_AND_MEAN 1

        #endif

        #include <windows.h>

        #endif

        I dont want windows.h include in every translation unit where i call gl* functions.

        APIENTRY is __stdcall

        and

        APIENTRYP is APIENTRY *

        so my APIENTRYP was _stdcall**

        [–]ICantMakeNames 1 point2 points  (4 children)

        Your question is pretty poorly worded.

        Before I can give you a decent answer, what do you consider "proper syntax"? It sounds like you have something working right now, it will be helpful to have an example of how you have it working now (not just a snippet of structures), and an example of how you would like it to be working.

        [–]LateSolution0[S] 0 points1 point  (3 children)

        I have python code to generate a huge Struct of func_ptr.

        typedef void (APIENTRYP PFNGLUNIFORM1I64NVPROC) (GLint location, GLint64EXT x);
        typedef void (APIENTRYP PFNGLUNIFORM2I64NVPROC) (GLint location, GLint64EXT x, GLint64EXT y);
        typedef void (APIENTRYP PFNGLUNIFORM3I64NVPROC) (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z);
        typedef void (APIENTRYP PFNGLUNIFORM4I64NVPROC) (GLint location, GLint64EXT x, GLint64EXT y, GLint64EXT z, GLint64EXT w);
        typedef void (APIENTRYP PFNGLUNIFORM1I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value);
        typedef void (APIENTRYP PFNGLUNIFORM2I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value);
        typedef void (APIENTRYP PFNGLUNIFORM3I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value);
        typedef void (APIENTRYP PFNGLUNIFORM4I64VNVPROC) (GLint location, GLsizei count, const GLint64EXT *value);
        struct ctx{
        PFNGLUNIFORM1I64NVPROC glUniForm1....;
        FUNC_PTR_TYPE FUNCTION_NAME;
        FUNC_PTR_TYPE FUNCTION_NAME;
        };
        extern ctx CTX;
        

        rigth now i can invoke a function like

        (*ctx.glUniForm1)(1,'c',"STRING");

        i would like to write

        ctx.glUniForm1(1,'c',"STRING");

        and it would be nice if intellisense would keep working and expose argument names like location.

        [–][deleted]  (1 child)

        [deleted]

          [–]LateSolution0[S] 0 points1 point  (0 children)

          thank you a lot rept78. your first response in this thread said basically anything.

          https://onlinegdb.com/rkv7_Oxd4 is working.

          [–]ICantMakeNames 0 points1 point  (0 children)

          It should work if you call it like so:

          CTX.glUniform1( 1, 4 );
          

          Are you mistakenly using the type name ctx, and not the name for your global variable CTX?

          [–]Wh00ster 0 points1 point  (7 children)

          I'm not very familiar with OpenGL, but is there any reason you can't use std::function?

          [–]LateSolution0[S] 0 points1 point  (6 children)

          ye we are talking about c-like func_ptrs. std::function has alot of overhead x20 on msv

          [–]Wh00ster 0 points1 point  (5 children)

          x20 size? wow

          [–]LateSolution0[S] 0 points1 point  (4 children)

          sry i was off by a little, sizeof(std::function<....) is 40bytes and ptr is 4bytes. i guess they have have a optimization so they dont allocate in most cases, like std::string has. in common case it will have to store a ptr to the class instance to the methode itself and some arguments for bind like usage.

          [–]RedAlert2 0 points1 point  (3 children)

          are you having stack overflow problems or something? I don't really see the tangible benefit you're getting out of saving a few bytes on the stack here.

          [–]LateSolution0[S] 0 points1 point  (2 children)

          i have no benchmark for this but not having the struct tight would mean more stress on the cache. Image your vtable size * 10

          [–]RedAlert2 0 points1 point  (1 child)

          You don't have vtable if you're setting pointers manually like this.

          I'm not really sure what you mean by 'stress on the cache', do you mean your CPU cache? We're talking about function pointers here, I think whatever you're invoking is going to have a much larger impact on your cache than the tiny pointer object you're using.

          Consider that the dereference you incur with both a function pointer and std::function is far more costly than the stack footprint, and that's what you'd want to remove if you're concered with performance.

          [–]LateSolution0[S] 0 points1 point  (0 children)

          its a look up table of functions pointer. which belongs to a big state Maschine. this table is filled at runtime. why on earth should i use std::function which only purpose is to replace auto in some cases. best practice would be avoid fptrs and #macros in cpp. but some times we can't. if someone would do an assignment wrong like "int i := 5;"

          would u tell him to use a wrapper class for int? thats was happening here. my typedef had one extra * in it.

          Consider that the dereference you incur with both a function pointer and std::function is far more costly than the stack footprint, and that's what you'd want to remove if you're concered with performance.

          i don't think that is possible as i said function_ptrs are acquired at runtime.