| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| Gizz 
 
 
 Joined: 15 Jun 2004
 Posts: 21
 Location: Nottingham UK
 
 
			    
 
 | 
			
				| Simple C char* question, old C hacks please help! |  
				|  Posted: Wed Jun 16, 2004 7:01 am |   |  
				| 
 |  
				| Hi Well, I'm up and running with the CCS compiler, and its nicer (so far) than the Hi-Tech one. But I seem to be forgetting my C (I'm a C# hack these days...).
 
 I have the following:
 
 void SendMessage(char* msg)
 {
 printf(msg);
 putc(10);
 putch(13);
 }
 
 
 Calling this like so:
 SendMessage("A test message");
 results in garbage being sent down the RS232.
 
 Calling like so:
 char temp[100];
 strcpy(temp, "A test message");
 SendMessage(temp);
 works just fine.
 
 Anyone know why the first instance fails?
 
 Its an 877A using the PICDEM2 and ICD2
 
 TIA!
 |  | 
	
		|  | 
	
		| Ttelmah Guest
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				| Re: Simple C char* question, old C hacks please help! |  
				|  Posted: Wed Jun 16, 2004 8:07 am |   |  
				| 
 |  
				|  	  | Gizz wrote: |  	  | Hi Well, I'm up and running with the CCS compiler, and its nicer (so far) than the Hi-Tech one. But I seem to be forgetting my C (I'm a C# hack these days...).
 
 I have the following:
 
 void SendMessage(char* msg)
 {
 printf(msg);
 putc(10);
 putch(13);
 }
 
 
 Calling this like so:
 SendMessage("A test message");
 results in garbage being sent down the RS232.
 
 Calling like so:
 char temp[100];
 strcpy(temp, "A test message");
 SendMessage(temp);
 works just fine.
 
 Anyone know why the first instance fails?
 
 Its an 877A using the PICDEM2 and ICD2
 
 TIA!
 | 
 Probably one of the most common "FAQ's" for the CCS compiler. It does not support pointers to constant strings (this is in the manual)...
 The second version, copies the constant string from ROM to RAM, and this can then be sent normally.
 A search through the forum, looking for comments like 'pointers to ROM', will find some of the thousands of posts about this.
 
 Best Wishes
 |  | 
	
		|  | 
	
		| SteveS 
 
 
 Joined: 27 Oct 2003
 Posts: 126
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Wed Jun 16, 2004 9:49 am |   |  
				| 
 |  
				| Oh, I see it's another one of your rude RTFM replies,  Ttelmah! 
 (big time just kidding!!!! - I couldn't resist)
 
 - SteveS
 |  | 
	
		|  | 
	
		| Gizz 
 
 
 Joined: 15 Jun 2004
 Posts: 21
 Location: Nottingham UK
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Wed Jun 16, 2004 9:55 am |   |  
				| 
 |  
				| OK, thanks, if I had a FM to FR I would! LOL! |  | 
	
		|  | 
	
		| Guest 
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				| Try this... |  
				|  Posted: Wed Jun 16, 2004 10:39 am |   |  
				| 
 |  
				| As it's just a constant message, you could use 
 puts( " this is a message" );
 
 Hans W
 |  | 
	
		|  | 
	
		| Guest 
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				|  |  
				|  Posted: Wed Jun 16, 2004 8:26 pm |   |  
				| 
 |  
				|  	  | Quote: |  	  | 
 void SendMessage(char* msg)
 {
 printf(msg);
 putc(10);
 putch(13);
 }
 
 
 Calling this like so:
 SendMessage("A test message");
 results in garbage being sent down the RS232.
 
 
 | 
 
 Sounds like a job for the C preprocessor.  A macro will behave like an inline function, and the compiler will generate the appropriate code for the context.
 |  | 
	
		|  | 
	
		| Ttelmah Guest
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				|  |  
				|  Posted: Thu Jun 17, 2004 10:57 am |   |  
				| 
 |  
				|  	  | Gizz wrote: |  	  | OK, thanks, if I had a FM to FR I would! LOL! | 
 The 'FM', is on the web...
 
 Best Wishes
  |  | 
	
		|  | 
	
		| Haplo 
 
 
 Joined: 06 Sep 2003
 Posts: 659
 Location: Sydney, Australia
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Jun 17, 2004 5:46 pm |   |  
				| 
 |  
				| Here it is: FM  |  | 
	
		|  | 
	
		|  |