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

How Does It Work?

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



Joined: 22 Feb 2007
Posts: 4

View user's profile Send private message

How Does It Work?
PostPosted: Thu Mar 22, 2007 6:50 am     Reply with quote

Folks,

While reviewing code for a port our team will be doing, I ran accross these function definitions:
Code:
void LCD_write_nibble(byte n)
{
    output_bit(LCD_D4, n & 1);
    output_bit((LCD_D5, (n>>1) & 1);
    output_bit(LCD_D6, (n>>2) & 1);
    output_bit(LCD_D7, (n>>3) & 1);
    delay_cycles(1)
    output_high(LCD_E);
    delay_us(4);
    output_low(LCD_E);
}

void LCD_write_byte(byte addr, b)
{
    delay_us(80);
    output_low(LCD_E);
    delay_cycles(1);
    output_bit(LCD_RS, addr);
    LCD_write_nibble(b>>4);
    LCD_write_nibble(b & 0x0F);
}

void LCD_putc(char c)
{
    if(c)
        LCD_write_byte(1,c);
}


In the main() function the LCD_putc() function is envoked by:
Code:
LCD_putc("Some String");


I expected a compiler error or warning about type mismatch, but I did not get it. Instead, all the characters of the string showed up on the LCD. I checked the map file to find that the compiler generated a loop for the LCD_putc() function. Why did it do this?

The compiler is version 4.025 and the processor is a PIC 18F452. Any insight would be welcome.

Thanks,

Jim.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Thu Mar 22, 2007 7:40 am     Reply with quote

That is one of the CCS extensions to standard C. If you give a string to a function that takes a char the compiler creates a loop to execute the function on each character of the string. It is non-standard but sometimes very useful.
_________________
The search for better is endless. Instead simply find very good and get the job done.
JimT



Joined: 22 Feb 2007
Posts: 4

View user's profile Send private message

PostPosted: Thu Mar 22, 2007 8:06 am     Reply with quote

SherpaDoug

Thanks for the reply. We'll make sure we document it in the code.

Thanks,

Jim.
JimT



Joined: 22 Feb 2007
Posts: 4

View user's profile Send private message

PostPosted: Thu Mar 22, 2007 4:50 pm     Reply with quote

Closing question:

Is this extension covered in the CCS documentation? I'm looking for something to reference.

Thanks,

Jim.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 22, 2007 5:04 pm     Reply with quote

The March 2006 manual says this:
Quote:

A (non-standard) feature has been added to the compiler to help get
around the problems created by the fact that pointers cannot be created
to constant strings. A function that has one CHAR parameter will accept
a constant string where it is called. The compiler will generate a loop
that will call the function once for each character in the string.

Example:

void lcd_putc(char c )
{
... }

lcd_putc ("Hi There.");

I can't find it in the current manual.
JimT



Joined: 22 Feb 2007
Posts: 4

View user's profile Send private message

PostPosted: Fri Mar 23, 2007 6:27 am     Reply with quote

PCM Programmer,

Thanks for the reply, that's just what I was looking for.

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