[C-safe-secure-studygroup] Can or should the pointer to void type be considered or treated as a pointer to object type?

Fulvio Baccaglini fulvio_baccaglini at prqa.com
Thu May 31 15:53:48 BST 2018


This was a question left open at the meeting; I believe that the answer
in no.

The C99 standard says:

[C99-6.2.5-1] "Types are partitioned into object types (types that fully
describe objects), function types (types that describe functions), and
incomplete types (types that describe objects but lack information
needed to determine their sizes)."

[C99-6.2.5-19] The void type comprises an empty set of values; it is an
incomplete type that cannot be completed.

This can be seen as a classification of the type:

- object types
- function types
- incomplete types that can be completed - i.e. incomplete types except
for void
- incomplete types that cannot be completed - i.e. void

MISRA C:2012 section 8.11 "Pointer type conversions" defines the
classification adopted for specifying the rules in that section:

- Pointer to object
- Pointer to function
- Pointer to incomplete
- Pointer to void
- A null pointer constant, i.e. the value 0, optionaqlly cast to void *

The classifications look compatible to me.

Incidentally, the amplification of Rule 11.2, which specifically deals
with incomplete types, also states: "Although a pointer to void is also
a pointer to an incomplete type, this rule does not apply to pointers to
void as they are covered by Rule 11.5".

The most apparent difference between Rule 11.2 and Rule 11.5 is that
converting a pointer to object to pointer to incomplete type is banned,
while converting a pointer to object to a pointer to void is allowed:

~~~~~~~~>
struct S;

void f (int * x)
{
  (struct S *) x;  // violates Rule 11.2
  (void *) x;      // complies with Rule 11.5
}
<~~~~~~~~

Fulvio
---------------------------------------------------------------------------------------
 This email has been scanned for email related threats and delivered safely by Mimecast.
 For more information please visit http://www.mimecast.com
---------------------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.trustable.io/pipermail/c-safe-secure-studygroup/attachments/20180531/37b7b27a/attachment-0001.html>


More information about the C-safe-secure-studygroup mailing list