Structure pointer operator – Altera Nios II C2H Compiler User Manual
Page 69

Altera Corporation
9.1
3–29
November 2009
Nios II C2H Compiler User Guide
C-to-Hardware Mapping Reference
Consider the simple
struct
declaration shown in
Example 3–22. Structure Declaration
struct s
{
int element_a;
int element_b;
int element_c;
} my_struct;
In this example, the expression
(my_struct.c)
translates to the
following:
*((int *)((void *)&my_struct + 2*sizeof(int)))
Structure Pointer Operator ->
The structure pointer operator is used to access a single member of a
structure or union via a pointer to the structure or union. The structure
pointer operator behaves similarly to the member operator, except that
the left-hand side of the operator must be a pointer.
The structure pointer operation on a
struct(
e.g.
mystruct->a)
is
equivalent to
Example 3–23. Converted struct Pointer Operation
*((pointer_to_type_of_a) ((void *)mystruct + offset_of_a))
The structure pointer operation on a
union
(e.g.
myunion->a)
is
equivalent to
Example 3–24. Converted union Pointer Operation
*((pointer_to_type_of_a)myunion)