![]() |
CITS2002 Systems Programming |
next → | ![]() |
![]() |
||||
System-calls and system-defined structuresMost system-calls accept integers and pointers to characters as parameters, and typically return integer values indicating their success. When more information must be passed to a system-call, or the call needs to return multiple values, we employ system-defined (C11) structures defined in operating system provided header files.Accessing structures using pointersWe've seen that we can access fields of a structure using a single dot ('.' or fullstop).What if, instead of accessing the structure directly, we only have a pointer to a structure? We've seen "one side" of this situation, already - when we passed the address of a structure to a function: struct timeval start_time; gettimeofday( &start_time, NULL );The function gettimeofday(), must have been declared to receive a pointer: extern int gettimeofday( struct timeval *time, ......);Consider the following example, in which a pointer to a structure is returned from a function. We now use the → operator (pronounced the 'arrow', or 'points-to' operator) to access the fields via the pointer:
CITS2002 Systems Programming, Lecture 16, p1, 19th September 2023.
|