Re: Question about 'C' code and use of "void"

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



"Stick" <Stick@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:52F0E3D7-E25F-4865-9E1E-3DDF3CC7151E@xxxxxxxxxxxxx
In code I'm reviewing I see this:

typedef void *PVOID; // <-- This line troubles me.
typedef PVOID *PPVOID;

And I'm confused becasue void is, of course, a keyword. Looks like
someone is trying to redefine the meaning of void, but I'm at a lose
as to why.

Stick

You are confusing #define syntax with typedef syntax. In simple cases,
typedef syntax is the "other way around" so that the last identifier is the
thing being defined.

More generally, typedef syntax is deliberately meant to mirror variable
declaration syntax. To define a new typename, you write the code for
declaring an instance of that type, then put typedef in front of the
declaration. Your variable name then becomes a typename.

Thus

int INT;

declares a variable called INT of type int, while

typedef int INT;

declares a typename called INT that is an alias for int.

Similarly

void * PVOID;

declares a variable called PVOID of type void *, while

typedef void * PVOID;

declares a typename called PVOID that is an alias for void *.

It works for function pointers to. Thus

void (*fnptr)(int);

declares a variable called fnptr that is a pointer to a function that takes
an int argument and returns void, whereas

typedef void (*fnptr)(int);

declares a typename called fnptr that is an alias for the type of a pointer
to a function that takes an int argument and returns void.


--
John Carson


.



Relevant Pages

  • Help in Java swings(internal Frame)
    ... public int getSize() ... public void valueChanged{ ... private JScrollPane scrollPane1; ... public class PeakContainer extends JInternalFrame ...
    (comp.lang.java.programmer)
  • [PATCH] get rid if __cpuinit and __cpuexit
    ... unsigned long action, void *hcpu) ... unsigned int cpu = hcpu; ... -static int __cpuinit ... __cpu_up(unsigned int cpu) ...
    (Linux-Kernel)
  • [PATCH,RFC 2.6.14 09/15] KGDB: SuperH-specific changes
    ... This adds basic support for KGDB on SuperH as well as adding some architecture ... -static int kgdb_uart_getchar ... -static void kgdb_uart_putchar ... * The command-line option can include a serial port specification ...
    (Linux-Kernel)
  • problem in java swings
    ... public int getSize() ... public void valueChanged{ ... private JScrollPane scrollPane1; ... public class PeakContainer extends JInternalFrame ...
    (comp.lang.java.programmer)
  • ToolTips in a View and TTN_NEEDTEXT
    ... extern int g_minWorkPeriod; ... void CDayView::CreateAllFonts ... void CDayView::DrawDayLog(CDC* pDC) ... BOOL CDayView::TimeToY ...
    (microsoft.public.vc.mfc)