Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

const char* error when compiling

Status
Not open for further replies.

maria258

Member level 2
Joined
Feb 10, 2011
Messages
42
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Activity points
1,577
I am using mplab hitech pic16f877a, and am trying to compile these:

1. void PutLogo(const char * logo)
2. void PutMessage(static char *Message)
3. PutMessage(( char*)"\x16\x38\x18Graphic demo.");

Is there any other way to change these around so that the compiler can build this program without errors? I tried to find an alternative using the maual but couldnt understand what to do.
thanks
Maria
 

bigdogguru

Administrator
Joined
Mar 12, 2010
Messages
9,831
Helped
2,348
Reputation
4,690
Reaction score
2,274
Trophy points
1,413
Location
Southwest, USA
Activity points
62,509
Can you post the exact compile log with errors?

Uploading your project would be very helpful as well.

If not please post the code snippets relevant to the error messages.
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
47,967
Helped
14,147
Reputation
28,553
Reaction score
12,834
Trophy points
1,393
Location
Bochum, Germany
Activity points
278,259
The problem is related to the question, if the Hitec compiler has any means to represent ROM pointers and how they are dereferenced. Unfortunately I'm not familiar with Hitech. I guess, you'll rather find the answer in the Hitech forum.

You can of course use a *char pointer and copy the constant string to a buffer before calling the function, but I guess, that's exactly what you want to avoid? It's however pretty clear, that you can't simply type cast a constant string to regular string with a PIC16 or PIC18 processor.
 
Last edited:

bigdogguru

Administrator
Joined
Mar 12, 2010
Messages
9,831
Helped
2,348
Reputation
4,690
Reaction score
2,274
Trophy points
1,413
Location
Southwest, USA
Activity points
62,509
The error in line three can be most likely corrected by the following code snippet:

const char * cp = "\x16" "\x38" "\x18" "Graphic demo.";

PutMessage(cp);

Two adjacent string constants (i.e. two strings separated only by white space) are concatenated by the compiler. Thus:

const char * cp = "hello" "world";
The Hi-Tech C Compiler requires closing and re-opening the quotes following escapes when forming literals.

Thus, use "\x42" "AH" for "BAH".

I am fairly familiar with the Hi-Tech C Compiler as it is my compiler of choice for PICs.
I believe I could help you solve the other two errors, but I will need to see your code to fully understand the context of the error messages.
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
47,967
Helped
14,147
Reputation
28,553
Reaction score
12,834
Trophy points
1,393
Location
Bochum, Germany
Activity points
278,259
The error in line three can be most likely corrected by the following code snippet:
const char * cp = "\x16" "\x38" "\x18" "Graphic demo.";
PutMessage(cp);
According to the above function prototype, *Message is a RAM pointer. I don't see, how Hitech C will be able to generate a pointer to cp without copying the string to RAM.
 

bigdogguru

Administrator
Joined
Mar 12, 2010
Messages
9,831
Helped
2,348
Reputation
4,690
Reaction score
2,274
Trophy points
1,413
Location
Southwest, USA
Activity points
62,509
Actually, unlike the first two, it's not a function prototype, it's a function call.

They're attempting to cast a literal as a "char * " from "const char * " and we both know that isn't going to happen.

So I assumed out of their frustration they were trying "everything" in an attempt to solve the problem of forming a literal with escape characters.

Otherwise they would have attempted to create an array of characters including the escapes and passed it to the function.

Frankly, this is why we need to see their entire code listing. We can make suggestions all day long, but without knowing the full context it's pointless.
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
47,967
Helped
14,147
Reputation
28,553
Reaction score
12,834
Trophy points
1,393
Location
Bochum, Germany
Activity points
278,259
Actually, unlike the first two, it's not a function prototype, it's a function call.
I was referring to the function prototype void PutMessage(static char *Message)
We can make suggestions all day long, but without knowing the full context it's pointless.
I agree. Primarly I wasn't guessing about the original problem. I just stated, that a ROM pointer respectively a const string won't be accepted as actual parameter.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top