Is void** an acceptable type in ANSI-C?

前端 未结 6 1883
余生分开走
余生分开走 2021-01-05 10:06

I have seen a function whose prototype is:

int myfunc(void** ppt)

This function is called in a C file as a = myfunc(mystruct **var1);<

6条回答
  •  感情败类
    2021-01-05 10:25

    Yes, void ** is perfectly acceptable and quite useful in certain circumstances. Also consider that given the declaration void **foo and void *bar, the compiler will know the size of the object pointed to by foo (it points to a pointer, and all pointers are the same size except on a few ancient platforms you needn't worry about), but it will not know the size of the object pointed to by bar (it could point to an object of any size). You can therefore safely perform pointer arithmetic on void ** pointers but not on void * pointers. You must cast them to something else first, like a char *. GCC will allow you to pretend that void * and char * are equivalent, each pointing to an object a single byte in size, but this is nonstandard and nonportable.

提交回复
热议问题