pythonctypes

Ctypes problem What is the difference between POINTER and pointer?


I am new to python ctypes, What is the difference between POINTER() and pointer() , and what are their functions?


Solution

  • POINTER() creates a type. pointer() creates an instance.

    For example, in C:

    typedef int* PINT;
    

    Would be:

    import ctypes
    PINT = ctypes.POINTER(ctypes.c_int)
    

    Whereas:

    int value = 5;
    int* p = &value;
    

    Would be:

    import ctypes
    value = ctypes.c_int(5)
    p = ctypes.pointer(value)