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

#define, how?

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



Joined: 30 Apr 2007
Posts: 44

View user's profile Send private message

#define, how?
PostPosted: Sun Dec 02, 2007 8:59 am     Reply with quote

Hi
I'm using usb_cdc.h and I do not want to write printf(usb_cdc_putc,"something") every time i want to write to rs232 via USB. Is there a way to make a define so that I only need to write cdc_printf("Something")? Or is there another way? I have tried to make a define, but I don't know how to do..

/miniman
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Dec 02, 2007 2:19 pm     Reply with quote

The following macro allows you to display a string by using the syntax
shown in your post.
Code:

#define cdc_printf(x) printf(usb_cdc_putc, "%s", x)

//======================================
void main()
{
cdc_printf("Hello World\n\r");

while(1);
}
Miniman



Joined: 30 Apr 2007
Posts: 44

View user's profile Send private message

PostPosted: Mon Dec 03, 2007 11:40 am     Reply with quote

Thank you.
But that willl only work for a string. Isn't there a way of doing it so that there are NO limitations, just lite the printf itself? I guess not.. I can not come up with any way of doing it.. Do you?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 03, 2007 1:36 pm     Reply with quote

Look in this CCS example file for another example:
Quote:
c:\Program Files\picc\Examples\Ex_Macro.c
Storic



Joined: 03 Dec 2005
Posts: 182
Location: Australia SA

View user's profile Send private message Send e-mail

PostPosted: Mon Dec 03, 2007 2:05 pm     Reply with quote

why not do a function
maybe something like this, I have not tested however compiles
Code:
unsigned char myprint(char *pntchr) {
  unsigned int8 cnt = 0;

  while (pntchr[cnt]) {
    putc(pntchr[cnt]);
    cnt++;
  }
}//~

_________________
What has been learnt if you make the same mistake? Wink
Miniman



Joined: 30 Apr 2007
Posts: 44

View user's profile Send private message

PostPosted: Tue Dec 04, 2007 9:34 am     Reply with quote

Quote:
why not do a function

Simply because then I won't be able to use %-statements lite %u %X etc...
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