What is the effect of dropping the pointer void function?

So, I'm trying to write a buffering library for the 64th time, and I'm starting to understand pretty advanced things. I thought that I would ask for some professional materials about this.

In my first header file, I have the following:

typedef struct StdBuffer { void* address; } StdBuffer;
extern void StdBufferClear(StdBuffer);

In another header file that #includeshas the first header file, I:

typedef struct CharBuffer { char* address; } CharBuffer;
void (*CharBufferClear)(CharBuffer) = (void*) StdBufferClear;

Will this function declare a void pointer to interfere with the call? They have a value comparison. I had never seen a function pointer declared by void before, but its only way to get it to compile.

Stackwise, this should not make any difference from what I learned in assembler coding.

irrelevant OMG! I just said Stackwise on StackOverflow!

.. , . , . , "" . , , "" . API, :

typedef struct StdBuffer {

    size_t width;        ///< The number of bytes that complete a data unit.
    size_t limit;        ///< The maximum number of data units that can be allocated for this buffer.
    void * address;      ///< The memory address for this buffer.
    size_t index;        ///< The current unit position indicator.
    size_t allocated;    ///< The current number of allocated addressable units.
    StdBufferFlags flags;///< The API contract for this buffer.

} StdBuffer;

, memcpy, memmove .. , , , - , .

, :

typedef struct CharBuffer {

    size_t width;        ///< The number of bytes that complete a data unit.
    size_t limit;        ///< The maximum number of data units that can be allocated for this buffer.
    char * address;      ///< The memory address for this buffer.
    size_t index;        ///< The current unit position indicator.
    size_t allocated;    ///< The current number of allocated addressable units.
    CharBufferFlags flags;///< The API contract for this buffer.

} CharBuffer;

, . , C - , address address, a byte byte, long long .

, C, , , ( )... , . , , (1, 2, 4, 8, sizeof (RandomStruct)), .

api, . , , , - . CharBuffer, .

StdBuffer - , EVER, api, , .

, , . @ Google. , , , , api .

, Signed/Unsigned bit StdBufferFlags.

, .

/** \def BIT(I)
    \brief A macro for setting a single constant bit.
 *
 *  This macro sets the bit indicated by I to enabled.
 *  \param I the (1-based) index of the desired bit to set.
 */
 #define BIT(I) (1UL << (I - 1))

/** \enum StdBufferFlags
    \brief Flags that may be applied to all StdBuffer structures.

 *  These flags determine the contract of operations between the caller
 *  and the StdBuffer API for working with data. Bits 1-4 are for the
 *  API control functions. All other bits are undefined/don't care bits.
 *
 *  If your application would like to use the don't care bits, it would
 *  be smart not to use bits 5-8, as these may become used by the API
 *  in future revisions of the software.

*/
typedef enum StdBufferFlags {

    BUFFER_MALLOCD = BIT(1),    ///< The memory address specified by this buffer was allocated by an API
    BUFFER_WRITEABLE = BIT(2),  ///< Permission to modify buffer contents using the API
    BUFFER_READABLE = BIT(3),   ///< Permission to retrieve buffer contents using the API
    BUFFER_MOVABLE = BIT(4)     ///< Permission to resize or otherwise relocate buffer contents using the API

}StdBufferFlags;
0
4

:

void (*CharBufferClear)(CharBuffer) = (void*) StdBufferClear;

void * . C void * , . ( ++ void * , .)

, ..:

void (*CharBufferClear)(CharBuffer) = (void (*)(CharBuffer)) StdBufferClear;

- , . , StdBuffer, , CharBuffer.

. C. , , , , .

, , , , " " "32- ". , , .

( : unsigned int unsigned long, ) C , , . , , A B . A->member, C , B->member , A->member B->member , , char *, void *. B->member , A->member. .

+3

void *.

undefined.

+1

, , C, , 99% C , -. , , , , . C , a void* a char* , , , , - . , , . -- [, , , ) , char* , , void* , , , , , LSB/MSB). , void* , char*, .

0

, , . , C .

-1

Source: https://habr.com/ru/post/1686282/


All Articles