Mikroc – ABL electronic PIC Microcontrollers PIC16 User Manual

Page 83

Advertising
background image

Note that you can omit structure tag, but then you cannot declare additional
objects of this type elsewhere. For more information, see the “Untagged
Structures” below.

Structure is initialized by assigning it a comma-delimited sequence of values with-
in braces, similar to array. Referring to declarations from the previous example:

/* Declare and initialize dots p and q: */

struct

Dot p = {1., 1.}, q = {3.7, -0.5};

/* Initialize already declared circles o1 and o2: */

o1 = {1, {0, 0}};

// r is 1, center is at (0, 0)

o2 = {4, { 1.2, -3 }};

// r is 4, center is at (1.2, -3)

Incomplete Declarations

Incomplete declarations are also known as forward declarations. A pointer to a
structure type

A

can legally appear in the declaration of another structure

B

before

A

has been declared:

struct

A;

// incomplete

struct

B {struct A *pa;};

struct

A {struct B *pb;};

The first appearance of

A

is called incomplete because there is no definition for it

at that point. An incomplete declaration is allowed here, because the definition of

B

doesn’t need the size of

A

.

Untagged Structures and Typedefs

If you omit the structure tag, you get an untagged structure. You can use untagged
structures to declare the identifiers in the comma-delimited

struct-id-list

to

be of the given structure type (or derived from it), but you cannot declare addition-
al objects of this type elsewhere.

It is possible to create a typedef while declaring a structure, with or without a tag:

typedef struct

{ ... } Mystruct;

Mystruct s, *ps, arrs[10];

MikroElektronika: Development tools - Books - Compilers

75

page

mikroC - C Compiler for Microchip PIC microcontrollers

mikroC

making it simple...

Advertising
This manual is related to the following products: