<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: C Program Array Question in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/c-program-array-question/m-p/5321643#M53175</link>
    <description>&lt;P&gt;&amp;gt; Can you tell me,﻿ [...]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; I could, but a Web (Google or other) search for keywords like, say:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C "type cast"&lt;BR /&gt;should save me the effort.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; GCC apparently hates only char-sized subscript values, while it&lt;BR /&gt;adores int-sized subscript values, so converting ("type casting") the&lt;BR /&gt;char-sized subscript to an int satisfies the compiler.&lt;/P&gt;</description>
    <pubDate>Mon, 05 Sep 2011 03:39:19 GMT</pubDate>
    <dc:creator>Steven Schweda</dc:creator>
    <dc:date>2011-09-05T03:39:19Z</dc:date>
    <item>
      <title>C Program Array Question</title>
      <link>https://community.hpe.com/t5/operating-system-linux/c-program-array-question/m-p/5321515#M53172</link>
      <description>&lt;P&gt;Hello Folks;&lt;BR /&gt;&lt;BR /&gt;I wrote a program to convert strings of ASCII text to ITA#2 - to test Teletype machines.&lt;BR /&gt;&lt;BR /&gt;Here's a sample string:&lt;BR /&gt;&lt;BR /&gt;char&amp;nbsp;&amp;nbsp;&amp;nbsp; QBF[ ]&amp;nbsp; = "THE QUICK BROWN FOX JUMPED OVER THE LAZY DOGS BACK "&lt;BR /&gt;&lt;BR /&gt;Here's the info on the translation table:&lt;BR /&gt;&lt;BR /&gt;int&amp;nbsp;&amp;nbsp;&amp;nbsp; atoi[128];&lt;BR /&gt;atoi[0] = 020;&lt;BR /&gt;atoi[1] = 022;&lt;BR /&gt;atoi[2] = 037;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* LTRS key */&lt;BR /&gt;...&lt;BR /&gt;atoi[127] = 000;&lt;BR /&gt;&lt;BR /&gt;---&lt;BR /&gt;Here the function:&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while(QBF[curchar] != '\0')&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; buffer = QBF[curchar];&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (void)write(dataout, &amp;amp;atoi[buffer], 1);&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ++curchar;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&lt;BR /&gt;-----&lt;BR /&gt;"buffer = QBF[curchar]"&amp;nbsp; sets "buffer" to the octal value of the current ASCII char, which is then added to the itoa table to create an offset to the ITA#2 character. It works fine - but it seems to me that I could get rid of the "buffer = QBF[curchar]" statement if I could code the "write's" arguments correctly. I have not been able to do so. The closest I've come is:&amp;nbsp; "(void)write(dataout, &amp;amp;atoi[(QBF[curchar])], 1);" and although that does work, the compiler complains with:&lt;BR /&gt;&lt;BR /&gt;ttytest.c: In function `main':&lt;BR /&gt;ttytest.c:327: warning: array subscript has type `char'&lt;BR /&gt;&lt;BR /&gt;Any ideas how to do this?&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;tony&lt;BR /&gt;&lt;BR /&gt;﻿&lt;/P&gt;</description>
      <pubDate>Sun, 04 Sep 2011 22:51:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/c-program-array-question/m-p/5321515#M53172</guid>
      <dc:creator>tony j. podrasky</dc:creator>
      <dc:date>2011-09-04T22:51:31Z</dc:date>
    </item>
    <item>
      <title>Re: C Program Array Question</title>
      <link>https://community.hpe.com/t5/operating-system-linux/c-program-array-question/m-p/5321597#M53173</link>
      <description>&lt;P&gt;&amp;nbsp;&amp;nbsp; I believe that this warning is a feature of recent GCC versions.&lt;BR /&gt;It's not immediately obvious to me why it's a good idea, but I haven't&lt;BR /&gt;tried to find out.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (void)write(dataout, &amp;amp;atoi[(QBF[curchar])], 1);&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; If it hates a char as a subscript, then have the compiler convert&lt;/P&gt;&lt;P&gt;("type cast") it to something it likes better.&amp;nbsp; Untested (but what could&lt;BR /&gt;go wrong?):&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (void)write(dataout, &amp;amp;atoi[(int)(QBF[curchar])], 1);&lt;BR /&gt;&lt;BR /&gt;(With my weak psychic powers, I can't see what "curchar" is, but I'll&lt;BR /&gt;assume that the complaint is about "QBF[]", not "curchar".)&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; Note that "atoi" is the name of a standard C library function, so&lt;BR /&gt;using it as the name of your look-up table might be more confusing than&lt;BR /&gt;wise.&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; man atoi&lt;/P&gt;</description>
      <pubDate>Mon, 05 Sep 2011 02:12:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/c-program-array-question/m-p/5321597#M53173</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2011-09-05T02:12:49Z</dc:date>
    </item>
    <item>
      <title>Re: C Program Array Question</title>
      <link>https://community.hpe.com/t5/operating-system-linux/c-program-array-question/m-p/5321641#M53174</link>
      <description>&lt;P&gt;Hello Steven;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your fix. Works great!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you tell me, without using up too much of your time, what the "(int) does to the statement to make it work?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again, Thank you for your input.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;P.S. Yes, - I know atoi is a library function - and one that I'm sure glad exists - but this little program is self-contained&lt;/P&gt;&lt;P&gt;and all it does is convert strings of ASCII into the 5-level code that Teletype machine use.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;tony&lt;/P&gt;</description>
      <pubDate>Mon, 05 Sep 2011 03:29:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/c-program-array-question/m-p/5321641#M53174</guid>
      <dc:creator>tony j. podrasky</dc:creator>
      <dc:date>2011-09-05T03:29:28Z</dc:date>
    </item>
    <item>
      <title>Re: C Program Array Question</title>
      <link>https://community.hpe.com/t5/operating-system-linux/c-program-array-question/m-p/5321643#M53175</link>
      <description>&lt;P&gt;&amp;gt; Can you tell me,﻿ [...]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; I could, but a Web (Google or other) search for keywords like, say:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; C "type cast"&lt;BR /&gt;should save me the effort.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; GCC apparently hates only char-sized subscript values, while it&lt;BR /&gt;adores int-sized subscript values, so converting ("type casting") the&lt;BR /&gt;char-sized subscript to an int satisfies the compiler.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Sep 2011 03:39:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/c-program-array-question/m-p/5321643#M53175</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2011-09-05T03:39:19Z</dc:date>
    </item>
    <item>
      <title>Re: C Program Array Question</title>
      <link>https://community.hpe.com/t5/operating-system-linux/c-program-array-question/m-p/5321647#M53176</link>
      <description>&lt;P&gt;&amp;gt;Here's the info on the translation table:&lt;BR /&gt;&amp;gt;int atoi[128];&lt;BR /&gt;&amp;gt;atoi[0] = 020;﻿&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If this is fixed, you should make it a static const with an initializer list.&amp;nbsp; Also, octal is so last century, you should be using hex.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;buffer = QBF[curchar];﻿&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is a bad name.&amp;nbsp; This is a "temp" or "index", not a "buffer".&amp;nbsp; A buffer is usually an array.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;(void)write(dataout, &amp;amp;atoi[buffer], 1);﻿&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You should be using fwrite(3) so you get buffering.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;sets "buffer" to the octal value of the current ASCII char﻿&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;No, it just sets it to the value of the char.&amp;nbsp; Also are you worried about NLS chars that are signed?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;The closest I've come is:&amp;nbsp; "(void)write(dataout, &amp;amp;atoi[(QBF[curchar])], 1);" and although that does work, the compiler complains with:﻿&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You just shut it up with a cast hammer.&lt;/P&gt;&lt;P&gt;(void)write(dataout, &amp;amp;atoi[((int)QBF[curchar])], 1)﻿&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is another problem with this write.&amp;nbsp; You are writing one byte but your buffer size is one int.&amp;nbsp; You need to change your atoi to an unsigned char or you need to write with "sizeof(int)".&amp;nbsp; While this may work in bogus little endian mode, you shouldn't depend on it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(You might want to remove the solution mark from your post and put it on Steven's.&amp;nbsp; See the post Options menu to the right.)&lt;/P&gt;</description>
      <pubDate>Mon, 05 Sep 2011 05:31:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/c-program-array-question/m-p/5321647#M53176</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2011-09-05T05:31:50Z</dc:date>
    </item>
    <item>
      <title>Re: C Program Array Question</title>
      <link>https://community.hpe.com/t5/operating-system-linux/c-program-array-question/m-p/5322507#M53178</link>
      <description>&lt;P&gt;Hello Steven;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again thank you for your response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I didn't consider asking GOOGLE about C "type cast", but I did - and received 786K entries.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also cracked-open some of my books on C and found some information (in there) that I didn't understand before but now I do. I guess it's an osmosis thing: the more you work with something, the more things that you didn't understand become clear.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;tony&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Sep 2011 20:39:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/c-program-array-question/m-p/5322507#M53178</guid>
      <dc:creator>tony j. podrasky</dc:creator>
      <dc:date>2011-09-05T20:39:49Z</dc:date>
    </item>
    <item>
      <title>Re: C Program Array Question</title>
      <link>https://community.hpe.com/t5/operating-system-linux/c-program-array-question/m-p/5322525#M53179</link>
      <description>&lt;P&gt;Hello Dennis;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your input.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;If this is fixed, you should make it a static const with an initializer list.&amp;nbsp; Also, octal is so last century, you should be using hex.﻿&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't know what a static const would do to enhance the program.&lt;/P&gt;&lt;P&gt;I can read octal (and translate it) as fast as someone would read alphabetical characters - and since I'm working with 5-level Teletype machines it's kinda appropriate.&amp;nbsp; :-)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;gt;buffer = QBF[curchar];﻿&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;This is a bad name.&amp;nbsp; This is a "temp" or "index", not a "buffer".&amp;nbsp; A buffer is usually an array.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;﻿&lt;/P&gt;&lt;P&gt;Good point - but since Steven gave me the cure to the problem, "buffer" no longer exists.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;You should be using fwrite(3) so you get buffering.﻿&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'll look into that for future reference but right now I'm sending single character data at 22ms intervals and I am unable to measure the load on the cpu.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;(You might want to remove the solution mark from your post and put it on Steven's.&amp;nbsp; See the post Options menu to the right.)﻿&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my first post since HP removed ITRC.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am under the impression that the "solved" is applied to the topic, and not a specific individual.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't see a way to remove it in the "options" menu.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In any case I did give Steven a Kudo for each of his answers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;tony&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Sep 2011 21:00:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/c-program-array-question/m-p/5322525#M53179</guid>
      <dc:creator>tony j. podrasky</dc:creator>
      <dc:date>2011-09-05T21:00:07Z</dc:date>
    </item>
    <item>
      <title>Re: C Program Array Question</title>
      <link>https://community.hpe.com/t5/operating-system-linux/c-program-array-question/m-p/5322697#M53180</link>
      <description>&lt;P&gt;&amp;gt;I don't know what a static const would do to enhance the program.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It does the initialization at compile time and cuts down on the VM footprint.&amp;nbsp; It's a good habit to get into.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;gt;right now I'm sending single character data at 22ms intervals and I am unable to measure the load on the CPU.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again, a good habit to get into.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;I am under the impression that the "solved" is applied to the topic, and not a specific individual.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The topic has a BIG mark.&amp;nbsp; But the "Solved! Go to Solution.﻿" URL will go to the wrong post:&lt;/P&gt;&lt;P&gt;&lt;A href="http://h30499.www3.hp.com/t5/System-Administration/C-Program-Array-Question/m-p/5321641#M53174" target="_blank"&gt;http://h30499.www3.hp.com/t5/System-Administration/C-Program-Array-Question/m-p/5321641#M53174&lt;/A&gt;﻿&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;I don't see a way to remove it in the "options" menu.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's under the post option (with the small check), not topic:&lt;/P&gt;&lt;P&gt;&lt;A href="http://h30499.www3.hp.com/t5/System-Administration/C-Program-Array-Question/m-p/5322507#display_7" target="_blank"&gt;http://h30499.www3.hp.com/t5/System-Administration/C-Program-Array-Question/m-p/5322507#display_7&lt;/A&gt;﻿&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://h30499.www3.hp.com/t5/help/faqpage/faq-category-id/solutions#solutions" target="_blank"&gt;http://h30499.www3.hp.com/t5/help/faqpage/faq-category-id/solutions#solutions&lt;/A&gt;﻿&lt;BR /&gt;&lt;BR /&gt;&amp;gt;In any case I did give Steven a Kudo for each of his answers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes but you want future searchers to find the solution, not hunt for stars.&amp;nbsp; ;-)&lt;/P&gt;</description>
      <pubDate>Tue, 06 Sep 2011 04:43:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/c-program-array-question/m-p/5322697#M53180</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2011-09-06T04:43:04Z</dc:date>
    </item>
  </channel>
</rss>

