CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

typedef const char hello; << why is this invalid

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
LiamLiam



Joined: 21 Sep 2008
Posts: 7

View user's profile Send private message

typedef const char hello; << why is this invalid
PostPosted: Sun Sep 28, 2008 4:35 am     Reply with quote

Hi All

Currently trying to figure out why the following is invalid:

Code:
typedef const char hello;


when
Code:
typedef unsigned int8 hello;
works fine.

Running 3.249 PCH

Any ideas?

Many thanks
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: typedef const char hello; << why is this invalid
PostPosted: Sun Sep 28, 2008 9:46 am     Reply with quote

typedef defines an alternate name for an existing data type. In your example, "unsigned int8" is an existing data type. But "const" is not a data type. "const" is a storage class, like "static" and "extern", and so cannot be part of a typedef.

You can do this:
Code:

typedef char hello;
 . . .
const hello x;

_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
LiamLiam



Joined: 21 Sep 2008
Posts: 7

View user's profile Send private message

PostPosted: Sun Sep 28, 2008 10:40 am     Reply with quote

Hi RLScott

The thing is that I have purchased a LCD driver / display library written in ANSI C.

As a way of abstracting itself from the specific data types of the compiler, they have use typedef. An example is:

Code:
typedef GCONSTP char PGENERIC * PGCSTR;            /* Pointer to constant string (may be in ROM or RAM) */


They have used this syntax quite liberally, so to change it would be a real pain. Am I missing something?
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Sun Sep 28, 2008 10:54 am     Reply with quote

LiamLiam wrote:

Code:
typedef GCONSTP char PGENERIC * PGCSTR;   /* Pointer to constant string (may be in ROM or RAM) */

If GCONSTP is defined as a string that contains "const", then this is not ANSII C.

Edit: After further review, it appears that "const" is not actually a storage class, but is a qualifier borrowed from C++, so it may or may not be allowed, depending on the way a particular compiler treats it. But it is certainly not a data type.
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Sep 28, 2008 11:40 am     Reply with quote

A pointer to ROM data is effectively a separate data type with many compilers, but it isn't a portable construct.

Apart from the said syntax problem, you should be aware that the handling of ROM constants and particularly ROM pointers may be incompatible with CCS C's way of treating this stuff. You probably saw only the tip of the iceberg.
Ttelmah
Guest







PostPosted: Sun Sep 28, 2008 2:35 pm     Reply with quote

Worth understanding, that in ANSI, a 'const', is _not_ a ROM data definition. In ANSI, all 'const' implies is that the target data, is read-only, not read-write. This is really not implementable, in hardware that doesn't have memory manager hardware to stop writing to areas where it is not allowed. All CCS does for 'const', in ANSI mode, is to copy the ROM data to RAM, just like a normal variable, and block normal write operations. This though won't work for pointer based operations.
You might as well remove the 'const' from the declarations....

As a separate comment though, remember that #define can be used to give similar behaviour to typedef, for operations like this.

Best Wishes
LiamLiam



Joined: 21 Sep 2008
Posts: 7

View user's profile Send private message

PostPosted: Tue Sep 30, 2008 5:12 am     Reply with quote

Gents, thanks for your input and replies.

I have got the low level stuff working now (writing to screen etc), so the drivers have been of some [although little] value.

I will attempt to get the rest working, but as FvM pointed out there will undoubtedly be many more problems. It will be good for a challenge at least.

For anybody who is interested, these are the RAMTEX drivers.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group