How do I specify a pointer and the object it points to ?

Q.  How do I specify a pointer and the object it points to?

A.  A pointer is represented by a * (star) symbol: what is on the left of the star specifies what the pointer is pointing to, what is on the right of the star specifies details about the pointer itself.
Example: char * ptr;
specifies a pointer named 'ptr' pointing to a character. The character can be anywhere in the memory space (code or data - the pointer is said to be 'generic') and the pointer itself can be anywhere in the data space.

You can specify more details about both the pointer and the pointed object, like in
int code * idata foo;
specifies a pointer named 'foo', located in idata and pointing to a variable of type int, located in code.


The general rule is as follows (optional means that this part of the declaration is not mandatory):
pointer_storage-class-specifier (optional) pointed_object_definition (optional) * pointer_definition;
where
pointer_storage-class-specifier: one of: auto register static extern typedef at address
pointed_object_definition: type-specifier(optional) pointed_object_qualifier(optional) remark: type-specifier is recommended; at least one specifier is needed before star
pointer_definition: pointer_qualifier(optional) direct-declarator

type-specifier: one of: void char short int long float double signed unsigned struct-or-union-specifier enum-specifier typedef-name
pointed_object_qualifier: one of: code, data, idata, xdata generic and/or const and/or volatile
pointer-qualifier: one of: code, data, idata, xdata

The default space qualifier for the pointed_object_qualifier is: generic.
The default space qualifier for the pointer_qualifier and the pointed_object_qualifier in case the NOGENERIC pragma is defined is:

  • models TINY and SMALL: data,
  • model COMPACT:pdata
  • models LARGE and HUGE:xdata.

More examples:

at 0xA0 char * idata pchar_data;
pchar_data defines a pointer located in idata at address 0xA0 pointing to a char.

extern int code * data pint_fcode;
pint_fcode defines an extern pointer located in data pointing to an integer located in code.

typedef char data * ptype;
ptype defines the type of a pointer pointing to a char in data.
Remember: no pointer-qualifier is allowed with typedef as pointer_storage-class-specifier!