Hi,

I am allocating memory for some areas. For DB i need 1024 bytes, for DS 1024*2 bytes and so on, and i initialised address as follows.

I initailise devBaseAddr to DB, because DB comes first, and next DC. DB is 1024 bytes , so for DC=DB+1024. This is DC address.

But there is an error in intialisation of DB address.
i.e in Line 8

DB=devBaseAddr;

Because devBaseAddr is of type char and DB is of type size_t.

How to assign address for DB i.e starting address of devBaseAddr;

void deviceBaseAddr()
{
	char *devBaseAddr;
	const size_t TotalDevMem = 1024+1024+1024*2+1024*4+1024*4+1024*8+1024*8+1024*8+1024*8+1024*8;  /*DB+DC+DS+DL+DF+DD+D+M+X+Y*/
	size_t DB, DC, DS, DL, DF, DD, D, M, X, Y;
	devBaseAddr=(char *)malloc(TotalDevMem);
	
	DB = devBaseAddr;
	DC = DB+1024;
	DS = DC+1024;
	DL = DS+1024*2;
	DF = DL+1024*4;
	DD = DF+1024*4;
	D = DD+ 1024*8;
	M = D + 1024*8;
	X = M + 1024*8;
	Y = X + 1024*8;
	size_t baseAddrTable[10] = { DB, DC, DS, DL, DF, DD, D, M, X, Y };

}

DB DC etc also need to be char* as well.
As does your baseAddrTable, it too needs to be an array of char*

DB DC etc also need to be char* as well.
As does your baseAddrTable, it too needs to be an array of char*

But if i make DB, DC as char its not possible to add 1024.

then how to add 1024 bytes to that

But if i make DB, DC as char its not possible to add 1024.

then how to add 1024 bytes to that

You need to make DB, etc pointers to char.

sizeof(char) is 1, by definition in the standard. So if DB is your base address, DB + 1024 is a pointer to a location 1024 bytes after DB.

Thanks i got my mistake.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.