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 support@ccsinfo.com

Seemingly Simple Syntax Question

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







Seemingly Simple Syntax Question
PostPosted: Wed Feb 26, 2003 4:13 pm     Reply with quote

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
PostPosted: Wed Feb 26, 2003 4:39 pm     Reply with quote

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

View user's profile Send private message

Re: Seemingly Simple Syntax Question
PostPosted: Wed Feb 26, 2003 5:11 pm     Reply with quote

:=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
PostPosted: Wed Feb 26, 2003 5:12 pm     Reply with quote

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
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