<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Array as Argument</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/14971/array-as-argument</link><description> I want to send control codes to a printer 
they look like this : 
 
 unsigned char cntrl_codes[6] = { 0x0d, 0x14, 0x1b, 0x4c, 0x0d, 0x0d}; 
 
I have made a function to send this array to serial port : 
 
//this function takes two arguments
// 1)the array</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Array as Argument</title><link>https://community.arm.com/thread/121783?ContentTypeID=1</link><pubDate>Mon, 10 Jun 2002 11:49:22 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:6c60c5e3-af7e-4433-a36a-4af431c074c0</guid><dc:creator>Mandar Limaye</dc:creator><description>&lt;p&gt;Thanks All&lt;br /&gt;
&lt;br /&gt;
I am using a null-term array and it works fine.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Array as Argument</title><link>https://community.arm.com/thread/110040?ContentTypeID=1</link><pubDate>Mon, 10 Jun 2002 09:37:07 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:92cf84f5-f86d-4f7a-b18b-afe8f6067159</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;pre&gt;while(*ptr!=0x0)&lt;/pre&gt;this, of course, requires that the string is &lt;b&gt;null-terminated&lt;/b&gt; (as any good &amp;#39;C&amp;#39; string should be - see K&amp;amp;R)&lt;br /&gt;
&lt;br /&gt;
this technique is fundamental to all of the &amp;#39;C&amp;#39; string-handling functions - they just keep going thro&amp;#39; the string til they hit a NUL!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Array as Argument</title><link>https://community.arm.com/thread/95073?ContentTypeID=1</link><pubDate>Mon, 10 Jun 2002 09:31:38 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:594adb88-8db2-40a6-aa06-5cad86a52672</guid><dc:creator>Alan Chen</dc:creator><description>&lt;p&gt;Try this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;
void TxSerial(unsigned char *ptr)
{   
    while(*ptr!=0x0)
    {
       SBUF=*ptr;     //Send one character
       while(!TI)     //Wait for completion
       {}
       TI=0;          //Clear Tx flag
       ptr++;
     }
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Array as Argument</title><link>https://community.arm.com/thread/95056?ContentTypeID=1</link><pubDate>Mon, 10 Jun 2002 08:07:51 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:50fd2214-f724-4708-ac24-7b0de3ec03db</guid><dc:creator>Mik Kleshov</dc:creator><description>&lt;p&gt;&lt;b&gt;strlen&lt;/b&gt; uses the trailing zero to find the length of the string. It could be implemented like this:&lt;br /&gt;
&lt;pre&gt;
int strlen(const char* str)
{
    int len = 0;
    while ( *str++ ) len++;
    return len;
}
&lt;/pre&gt;
The program code does not contain any runtime information about the size of the array. That&amp;#39;s how C works. So if you want the function to work with arrays of different sizes, you need to either pass the size explicitly or use tricks like &lt;b&gt;strlen&lt;/b&gt;, which requires trailing zero.&lt;br /&gt;
Compile-time information about the size of the array is available in the form of &lt;b&gt;sizeof(array)&lt;/b&gt;, where &lt;b&gt;array&lt;/b&gt; is the name of the array, it cannot be an argument to a function. So you don&amp;#39;t have to use &lt;b&gt;strlen&lt;/b&gt;, which takes time to scan the string. You can just pass &lt;b&gt;sizeof(array)&lt;/b&gt; as an argument, that&amp;#39;s how it&amp;#39;s ususally done.&lt;br /&gt;
- Mike&lt;br /&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Array as Argument</title><link>https://community.arm.com/thread/54453?ContentTypeID=1</link><pubDate>Mon, 10 Jun 2002 07:33:51 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:566b571a-f3e0-48b5-b228-1a56ea9a7d74</guid><dc:creator>Graham Cole</dc:creator><description>&lt;p&gt;It is not clear what the problem is.&lt;br /&gt;
&lt;br /&gt;
You could define your control codes as a null terminated string if you prefer:&lt;br /&gt;
&lt;pre&gt;
unsigned char cntrl_codes = &amp;quot;\0x0d\0x14\0x1b\0x4c\0x0d\0x0d&amp;quot;;
&lt;/pre&gt;
Is the problem that you do not want to hold up the CPU while waiting for the delay time? To do this it is necessary to buffer the output and to have a special version of putchar() that detects a non-ASCII command character and interprets it as a wait command. This may get more complicated that you really want...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Array as Argument</title><link>https://community.arm.com/thread/54452?ContentTypeID=1</link><pubDate>Mon, 10 Jun 2002 07:24:05 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:d38dde1c-8adf-4406-8250-9fefb8e418a8</guid><dc:creator>Mandar Limaye</dc:creator><description>&lt;p&gt;1) strlen does not give correct result&lt;br /&gt;
&lt;br /&gt;
2) trailing zero ... to make it NULL terminated ...why?&lt;br /&gt;
&lt;br /&gt;
3) i want a generalized func that can take arrays of different lengths....&lt;br /&gt;
&lt;br /&gt;
4) so should I use &amp;#39;strlen&amp;#39; in my main func to find size of array and then&lt;br /&gt;
   pass it as argument  ? how would that change it ?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Thanks&lt;br /&gt;
Mandar Limaye&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Array as Argument</title><link>https://community.arm.com/thread/38836?ContentTypeID=1</link><pubDate>Mon, 10 Jun 2002 07:08:04 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:2fc8e139-1b25-4e44-9ea7-6744806b97af</guid><dc:creator>Mik Kleshov</dc:creator><description>&lt;p&gt;Does the &lt;b&gt;strlen&lt;/b&gt; call give the result you want? There is no trailing zero in the initializer of the array. You have to pass the size of the array as an extra argument to the function.&lt;br /&gt;
Besides that, I can&amp;#39;t see why this function is ungraceful. You can declare it like this:&lt;br /&gt;
&lt;pre&gt;
void print(unsigned char c[],unsigned char del)
&lt;/pre&gt;
which may look better but doesn&amp;#39;t make any difference.&lt;br /&gt;
&lt;br /&gt;
Regards,&lt;br /&gt;
- Mike&lt;br /&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>