/*
** This program shows a bug in the c55x compiler.
** It shows that setting an address of a structure in a defined section
** to a pointer defined in the same section will use the Program Space
** address instead of the Data Space address.
** In other words, in those cases the stored address is multiplied by 2.
**
** Testing was tried with Code Generation Tools 4.3.9 and 4.1.2.
*/
#include <stdio.h>
typedef struct {
int first;
int second;
} MY_STRUCT;
#pragma DATA_SECTION(namedSection, ".const")
//#pragma DATA_SECTION(unnamedSection, ".const")
#pragma DATA_SECTION(ptrs, ".const")
#pragma DATA_SECTION(namedSectionPtr, ".const")
const MY_STRUCT namedSection[2] = {1, 2};
const MY_STRUCT unnamedSection[2] = {3, 4};
const MY_STRUCT * const namedSectionPtr = namedSection;
const MY_STRUCT * const unnamedSectionPtr = unnamedSection;
typedef struct{
const MY_STRUCT *namedSectionPtr;
const MY_STRUCT *unnamedSectionPtr;
}INFO_TAB;
const INFO_TAB ptrs = {namedSection, unnamedSection};
void main (void)
{
printf("address of namedSection is 0x%lx\n", (long)&namedSection);
printf("pointer to namedSection is 0x%lx. This is a bug!\n", (long)namedSectionPtr);
printf("pointer in struct to namedSection is 0x%lx. This is a bug!\n", (long)ptrs.namedSectionPtr);
printf("\n");
printf("address of unnamedSection is 0x%lx\n", (long)&unnamedSection);
printf("pointer to unnamedSection is 0x%lx\n", (long)unnamedSectionPtr);
printf("pointer in struct to unnamedSection is 0x%lx\n", (long)ptrs.unnamedSectionPtr);
}