To get a trial key
fill out the form below
Team License (a basic version)
Enterprise License (an extended version)
* By clicking this button you agree to our Privacy Policy statement

Request our prices
New License
License Renewal
--Select currency--
USD
EUR
GBP
RUB
* By clicking this button you agree to our Privacy Policy statement

Free PVS-Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

Message submitted.

Your message has been sent. We will email you at


If you haven't received our response, please do the following:
check your Spam/Junk folder and click the "Not Spam" button for our message.
This way, you won't miss messages from our team in the future.

>
>
>
Incomplete type

Incomplete type

Oct 01 2021

An incomplete type tells the compiler that a type with this name exists but it does not tell anything about how a type is implemented. For example, it doesn't tell what functions, variables are there. Usually, these types are fully defined later, so this declaration is often called a forward declaration.

Incomplete types include:

  • the void type;
  • structs, classes, and unions, for which an implementation has not yet been defined;
  • unknown size arrays;
  • arrays of elements of an incomplete type.

For the type to become complete (fully defined), we must specify the missing information. It is also worth noting the void type, which cannot be complete at all.

Limits when using incomplete types

An incomplete type does not tell the compiler anything about its internal structure. Thus, we cannot compile code that tries to access its contents. It is also impossible to perform operations that require knowledge of the exact type size. To do this, we need to know the size of the types that are contained in the required class.

Examples of incomplete types and ways to fully define them

We can obtain an incomplete type by using the following language constructs:

Forward - declaration:

class MyType;

Pointer to an unknown type:

struct MyType *myPtr;

An array containing elements of an incomplete type (even if the number of elements is known):

MyType b[10];

In all these cases, for a complete definition of the type, we are obliged to provide an implementation of the 'MyType' type somewhere. For example, this:

class MyType {
  int someNumber;
}

In this case, all restrictions imposed on incomplete types will be removed.

The situation with arrays of indeterminate size deserves a separate explanation since there are several nuances when using them. For example:

extern int a[];        // Incomplete type (an array of unknown 
   // size with the elements of the 'int' type)
int b[] = { 1, 2, 3 }; // Complete type 
                       // (an array of three values of the 'int' type)
int c[10];             // Complete type

Also, references and pointers can be created to arrays of unknown size, but in C++ they cannot be initialized (or assigned) by pointers to arrays with a known size. This restriction is absent in the C language because pointers to ordinary arrays and to arrays of unknown size are compatible there, and therefore can be freely converted and assigned in both directions.

extern int a[];
int (&a1)[]  = a;    // OK
int (*a2)[]  = &a;   // OK
int (*a3)[2] = &a;   // Error in C++, but correct in C
 
int b[] = {1, 2, 3};
int (&b1)[] = b;     // Error
int (*b2)[] = &b;    // Error in C++, but correct in C
Popular related articles
Technologies used in the PVS-Studio code analyzer for finding bugs and potential vulnerabilities

Date: Nov 21 2018

Author: Andrey Karpov

A brief description of technologies used in the PVS-Studio tool, which let us effectively detect a large number of error patterns and potential vulnerabilities. The article describes the implementati…
PVS-Studio ROI

Date: Jan 30 2019

Author: Andrey Karpov

Occasionally, we're asked a question, what monetary value the company will receive from using PVS-Studio. We decided to draw up a response in the form of an article and provide tables, which will sho…
The Last Line Effect

Date: May 31 2014

Author: Andrey Karpov

I have studied many errors caused by the use of the Copy-Paste method, and can assure you that programmers most often tend to make mistakes in the last fragment of a homogeneous code block. I have ne…
Characteristics of PVS-Studio Analyzer by the Example of EFL Core Libraries, 10-15% of False Positives

Date: Jul 31 2017

Author: Andrey Karpov

After I wrote quite a big article about the analysis of the Tizen OS code, I received a large number of questions concerning the percentage of false positives and the density of errors (how many erro…
The Ultimate Question of Programming, Refactoring, and Everything

Date: Apr 14 2016

Author: Andrey Karpov

Yes, you've guessed correctly - the answer is "42". In this article you will find 42 recommendations about coding in C++ that can help a programmer avoid a lot of errors, save time and effort. The au…
The Evil within the Comparison Functions

Date: May 19 2017

Author: Andrey Karpov

Perhaps, readers remember my article titled "Last line effect". It describes a pattern I've once noticed: in most cases programmers make an error in the last line of similar text blocks. Now I want t…
How PVS-Studio Proved to Be More Attentive Than Three and a Half Programmers

Date: Oct 22 2018

Author: Andrey Karpov

Just like other static analyzers, PVS-Studio often produces false positives. What you are about to read is a short story where I'll tell you how PVS-Studio proved, just one more time, to be more atte…
The way static analyzers fight against false positives, and why they do it

Date: Mar 20 2017

Author: Andrey Karpov

In my previous article I wrote that I don't like the approach of evaluating the efficiency of static analyzers with the help of synthetic tests. In that article, I give the example of a code fragment…
Static analysis as part of the development process in Unreal Engine

Date: Jun 27 2017

Author: Andrey Karpov

Unreal Engine continues to develop as new code is added and previously written code is changed. What is the inevitable consequence of ongoing development in a project? The emergence of new bugs in th…
Free PVS-Studio for those who develops open source projects

Date: Dec 22 2018

Author: Andrey Karpov

On the New 2019 year's eve, a PVS-Studio team decided to make a nice gift for all contributors of open-source projects hosted on GitHub, GitLab or Bitbucket. They are given free usage of PVS-Studio s…

Comments (0)

Next comments
This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site.
Learn More →
Accept