ARM Technical Support Knowledge Articles

POINTER TRUNCATION FOR IDENTICALLY DECLARED POINTERS

Applies to: C166 C Compiler

Answer


Information in this article applies to:


QUESTION

I compile the following code with the C166:

void main (void)  {

int huge *pTest1, *pTest2;
int huge *pTest3;

pTest1 = pTest3;
pTest2 = pTest3;

}

This generates:

*** WARNING C151: pointer truncation: 'huge' to 'near'.

Why are not all three pointers huge? Why does pTest2 point to near memory?

ANSWER

The memory type specifier huge in a pointer declaration list must be repeated for each pointer.

In your code example, pTest1 points to huge, but pTest2 points to the default memory space (which is near for the memory model Tiny, Small, or Medium).

You may avoid this by using a typedef:

typedef int huge H_INT;

void main (void)  {


H_INT *pTest1, *pTest2;
H_INT *pTest3;

pTest1 = pTest3;
pTest2 = pTest3;

}

Using the typedef, you can be sure that all declarations in the list have the same type.

MORE INFORMATION

Article last edited on: 2005-07-15 09:59:07

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential