Re: void* passed as funtion parameters?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Ulrich Eckhardt wrote:
Some suggestions:
1. You could use a union type to store the array and store the array
in the initial members of the struct, so that you can factor out a
base-struct that contains the pointer/size_t combo.
2. You could also attach the type to the struct itself, like in the
first member an enumeration. This would allow you to distinguish the
type easier. You could then treat the void pointer as pointer to the
enumeration, read it, and then treat the different types accordingly.
3. You could also attach a function-pointer for various things that
have common behaviour but actually different implementations for
different types.

4. Since the only thing these structs have in common is an accident of
having members with the same name, you could use a macro in place of a
function:

#define f(p) \
do { \
(p)->LK__F1 = 10; \
(p)->dc[0].LKdct__F1 = 20; \
} while (0)

But give your macro some long and ugly name other than "f".
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


.



Relevant Pages

  • Re: #defining an array within another in C language
    ... you do not know the number of elements of the array. ...     int var; ... C99 flexible array members or the plain old "struct hack". ...
    (comp.lang.c)
  • Re: C, strcat
    ... Actually a 1-length array of char. ... >members (all char strings) contained in a structure. ... struct member_data ...
    (alt.comp.lang.learn.c-cpp)
  • Re: structure toupperlower?
    ... >> I need to properly format the case of a struct. ... Are you trying to iterate over the members of a struct? ... you probably can if you first build an array each element ... The toupperand tolowerfunctions apply to a single character: ...
    (comp.lang.c)
  • Re: [patch 3/4 -mm] flex_array: poison free elements
    ... character as the poison value. ... If someone ever tried to store strings ... I wasn't aware that storing an array of ASCII characters was a use case ... distinguish when the elements are being stored in struct flex_array vs. ...
    (Linux-Kernel)
  • Re: Converting Bitmap into 2D-Array
    ... and convert it to a 2D array where each element represents one of the ... struct bitmap { ... Thank you for the advices.For my purposes i have to store grayscale ...
    (microsoft.public.vc.language)