|
|
View previous topic :: View next topic |
Author |
Message |
Jerry Finsen Guest
|
Seemingly Simple Syntax Question |
Posted: Wed Feb 26, 2003 4:13 pm |
|
|
The following snippet fails to compile the call to Test2: "Bad expression syntax:.
What am I missing?
include <16F877.h>
//********************************
// Prototypes
void Test1(Char String);
void Test2(int x, Char String);
//********************************
// Main
void main() {
Test1( "Hello World");
Test2(1, "Hello World");
}
//********************************
// Subroutines
void Test1(Char String)
{
return;
}
void Test2(int x, char String)
{
return;
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 12135 |
|
|
Hans Wedemeyer Guest
|
Re: Seemingly Simple Syntax Question |
Posted: Wed Feb 26, 2003 4:39 pm |
|
|
When you pass a string you are passing a char pointer.
I modified the code it should work now...
hansw
:=The following snippet fails to compile the call to Test2: "Bad expression syntax:.
:=
:=What am I missing?
:=
:=include <16F877.h>
:=//********************************
:=// Prototypes
:=void Test1(char* String);
:=void Test2(int x, char* String);
:=
:=//********************************
:=// Main
:=void main() {
:=
:=Test1( "Hello World");
:=Test2(1, "Hello World");
:=
:=}
:=
:=//********************************
:=// Subroutines
:=
:=void Test1(char* String)
:={
:=return;
:=}
:=
:=void Test2(int x, char* String)
:={
:=return;
:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 12141 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Seemingly Simple Syntax Question |
Posted: Wed Feb 26, 2003 5:11 pm |
|
|
:=The following snippet fails to compile the call to Test2: "Bad expression syntax:.
:=
:=What am I missing?
:=
-----------------------------------------------------------
CCS doesn't permit pointers to constant strings.
You have to copy the string to a ram buffer first.
Example:
<PRE>
#include "16F877.h"
#fuses HS, NOWDT,NOPROTECT,PUT,BROWNOUT, NOLVP
#use Delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
<BR>
void Test1(char* String);
//===============================
void main()
{
char temp[20];
<BR>
strcpy(temp, "Hello World");
<BR>
Test1(temp);
<BR>
while(1);
<BR>
}
<BR>
//===============================
void Test1(char* String)
{
printf("\%s", String);
}
</PRE>
___________________________
This message was ported from CCS's old forum
Original Post ID: 12142 |
|
|
Jerry Finsen Guest
|
Re: Seemingly Simple Syntax Question |
Posted: Wed Feb 26, 2003 5:12 pm |
|
|
I copied your code into the IDE and tried to compile ... same error. Mysterious that it doesn't complain about the call to Test1.
Using 3.146 of the compiler.
___________________________
This message was ported from CCS's old forum
Original Post ID: 12143 |
|
|
|
|
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
|