Dereferencing Pointer To Incomplete Type

Example

Let's say we have the following structure:

When the pointer is valid, we can dereference it to access its members using one of two different notations: int a = (.instance).myint; float b = instance-myfloat; While both these methods work, it is better practice to use the arrow - operator rather than the combination of parentheses, the dereference. operator and the dot. Jan 10, 2014  C Programming Tutorial 16: Dereferencing Pointer Variables in C (Memory to its content). Dereferencing pointer to incomplete type gcc. Dereferencing pointer to incomplete type c.

We can define MY_STRUCT to omit the struct keyword so we don't have to type struct MY_STRUCT each time we use it. This, however, is optional.

If we then have a pointer to an instance of this struct

If this statement appears at file scope, instance will be initialized with a null pointer when the program starts. If this statement appears inside a function, its value is undefined. The variable must be initialized to point to a valid MY_STRUCT variable, or to dynamically allocated space, before it can be dereferenced. For example:

When the pointer is valid, we can dereference it to access its members using one of two different notations:

While both these methods work, it is better practice to use the arrow -> operator rather than the combination of parentheses, the dereference * operator and the dot . operator because it is easier to read and understand, especially with nested uses.

Another important difference is shown below:

In this case, copy contains a copy of the contents of instance. Changing my_int of copy will not change it in instance.

In this case, ref is a reference to instance. Changing my_int using the reference will change it in instance.

It is common practice to use pointers to structs as parameters in functions, rather than the structs themselves. Using the structs as function parameters could cause the stack to overflow if the struct is large. Using a pointer to a struct only uses enough stack space for the pointer, but can cause side effects if the function changes the struct which is passed into the function.



Related Tags

Package: openssh;Maintainer for openssh is Debian OpenSSH Maintainers <debian-ssh@lists.debian.org>;

Reported by: jean-christophe manciot <actionmystique@gmail.com>

Date: Mon, 13 Mar 2017 11:36:02 UTC

Severity: normal

Found in version 7.4p1-7

Done: Colin Watson <cjwatson@debian.org>

Bug is archived. No further changes may be made.

View this report as an mbox folder, status mbox, maintainer mbox

Report forwardedto debian-bugs-dist@lists.debian.org, Debian OpenSSH Maintainers <debian-ssh@lists.debian.org>:
Bug#857621; Package openssh. (Mon, 13 Mar 2017 11:36:04 GMT) (full text, mbox, link).

Acknowledgement sentto jean-christophe manciot <actionmystique@gmail.com>:
New Bug report received and forwarded. Copy sent to Debian OpenSSH Maintainers <debian-ssh@lists.debian.org>. (Mon, 13 Mar 2017 11:36:04 GMT) (full text, mbox, link).

Message #5 received at submit@bugs.debian.org (full text, mbox, reply):

From: jean-christophe manciot <actionmystique@gmail.com>
Subject: error: dereferencing pointer to incomplete type ‘DSA {aka struct dsa_st}’

Reply sentto Colin Watson <cjwatson@debian.org>:
You have taken responsibility. (Mon, 13 Mar 2017 12:39:05 GMT) (full text, mbox, link).

Notification sentto jean-christophe manciot <actionmystique@gmail.com>:
Bug acknowledged by developer. (Mon, 13 Mar 2017 12:39:05 GMT) (full text, mbox, link).

Message #10 received at 857621-close@bugs.debian.org (full text, mbox, reply):

To: 857621-close@bugs.debian.org
Subject: Re: Bug#857621: error: dereferencing pointer to incomplete type ‘DSA {aka struct dsa_st}’

Information forwardedto debian-bugs-dist@lists.debian.org, Debian OpenSSH Maintainers <debian-ssh@lists.debian.org>:
Bug#857621; Package openssh. (Mon, 13 Mar 2017 13:57:05 GMT) (full text, mbox, link).

Acknowledgement sentto jean-christophe manciot <actionmystique@gmail.com>:
Extra info received and forwarded to list. Copy sent to Debian OpenSSH Maintainers <debian-ssh@lists.debian.org>. (Mon, 13 Mar 2017 13:57:05 GMT) (full text, mbox, link).

Message #15 received at 857621@bugs.debian.org (full text, mbox, reply):

From: jean-christophe manciot <actionmystique@gmail.com>
Subject: Re: Bug#857621 closed by Colin Watson <cjwatson@debian.org> (Re: Bug#857621: error: dereferencing pointer to incomplete type ‘DSA {aka struct dsa_st}’)

Information forwardedto debian-bugs-dist@lists.debian.org, Debian OpenSSH Maintainers <debian-ssh@lists.debian.org>:
Bug#857621; Package openssh. (Mon, 13 Mar 2017 14:15:03 GMT) (full text, mbox, link).

Acknowledgement sentto Colin Watson <cjwatson@debian.org>:
Extra info received and forwarded to list. Copy sent to Debian OpenSSH Maintainers <debian-ssh@lists.debian.org>. (Mon, 13 Mar 2017 14:15:03 GMT) (full text, mbox, link).

Message #20 received at 857621@bugs.debian.org (full text, mbox, reply):

To: jean-christophe manciot <actionmystique@gmail.com>, 857621@bugs.debian.org
Subject: Re: Bug#857621: closed by Colin Watson <cjwatson@debian.org> (Re: Bug#857621: error: dereferencing pointer to incomplete type ‘DSA {aka struct dsa_st}’)

Information forwardedto debian-bugs-dist@lists.debian.org, Debian OpenSSH Maintainers <debian-ssh@lists.debian.org>:
Bug#857621; Package openssh. (Mon, 13 Mar 2017 16:45:05 GMT) (full text, mbox, link).

Acknowledgement sentto jean-christophe manciot <actionmystique@gmail.com>:
Extra info received and forwarded to list. Copy sent to Debian OpenSSH Maintainers <debian-ssh@lists.debian.org>. (Mon, 13 Mar 2017 16:45:05 GMT) (full text, mbox, link).

Message #25 received at 857621@bugs.debian.org (full text, mbox, reply):

From: jean-christophe manciot <actionmystique@gmail.com>
Cc: 857621@bugs.debian.org
Subject: Re: Bug#857621: closed by Colin Watson <cjwatson@debian.org> (Re: Bug#857621: error: dereferencing pointer to incomplete type ‘DSA {aka struct dsa_st}’)

Microsoft word for mac fraction symbols. Information forwardedto debian-bugs-dist@lists.debian.org, Debian OpenSSH Maintainers <debian-ssh@lists.debian.org>:
Bug#857621; Package openssh. (Mon, 13 Mar 2017 17:09:07 GMT) (full text, mbox, link).

Acknowledgement sentto Colin Watson <cjwatson@debian.org>:
Extra info received and forwarded to list. Copy sent to Debian OpenSSH Maintainers <debian-ssh@lists.debian.org>. (Mon, 13 Mar 2017 17:09:07 GMT) (full text, mbox, link).

Message #30 received at 857621@bugs.debian.org (full text, mbox, reply):

To: jean-christophe manciot <actionmystique@gmail.com>
Subject: Re: Bug#857621: closed by Colin Watson <cjwatson@debian.org> (Re: Bug#857621: error: dereferencing pointer to incomplete type ‘DSA {aka struct dsa_st}’)

Information forwardedto debian-bugs-dist@lists.debian.org, Debian OpenSSH Maintainers <debian-ssh@lists.debian.org>:
Bug#857621; Package openssh. (Mon, 13 Mar 2017 18:27:06 GMT) (full text, mbox, link).

Acknowledgement sentto jean-christophe manciot <actionmystique@gmail.com>:
Extra info received and forwarded to list. Copy sent to Debian OpenSSH Maintainers <debian-ssh@lists.debian.org>. (Mon, 13 Mar 2017 18:27:06 GMT) (full text, mbox, link).

Message #35 received at 857621@bugs.debian.org (full text, mbox, reply):

From: jean-christophe manciot <actionmystique@gmail.com>
Cc: 857621@bugs.debian.org
Subject: Re: Bug#857621: closed by Colin Watson <cjwatson@debian.org> (Re: Bug#857621: error: dereferencing pointer to incomplete type ‘DSA {aka struct dsa_st}’)

Bug archived.Request was from Debbugs Internal Request <owner@bugs.debian.org>to internal_control@bugs.debian.org. (Tue, 11 Apr 2017 07:26:27 GMT) (full text, mbox, link).

Send a report that this bug log contains spam.

Debian bug tracking system administrator <owner@bugs.debian.org>.Last modified:Fri May 15 23:33:07 2020; Machine Name:beach

Debbugs is free software and licensed under the terms of the GNU Public License version 2. The current version can be obtained from https://bugs.debian.org/debbugs-source/.

Copyright © 1999 Darren O. Benham,1997,2003 nCipher Corporation Ltd,1994-97 Ian Jackson,2005-2017 Don Armstrong, and many other contributors.