title: How to handle negative or unsigned char when porting from C/C++ to JavaScript?
body: <p>I'm trying to port an old C++ lexer (<a href="https://github.com/julius-speech/julius/blob/6d135a686a74376495a7a6f55d3d67df54186f83/gramtools/mkdfa/mkfa-1.44-flex/lex.yy.c" rel="nofollow noreferrer">source</a>) to JavaScript and am struggling a bit with my non-comprehension of C/C++.</p>
  
  <p>I have a parameter <code>c</code> which as I currently see it could either be an index of the position on a chunk of an input file I'm parsing (<code>*yy_cp</code>) or the actual (including nul) character stored at this address. I need to use <code>c</code> as an index in a lookup table. The lexer does this:</p>
  
  <pre><code>/* Promotes a possibly negative, possibly signed char to an
   * unsigned integer for use as an array index.  If the signed char
   * is negative, we want to instead treat it as an 8-bit unsigned
   * char, hence the double cast.
   */
  #define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
  </code></pre>
  
  <p>and calls it like this:</p>
  
  <pre><code>register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
  </code></pre>
  
  <p>which will store the value of lookup table <code>yy_ec</code> which contains 256 entries (I assume extended ASCII), in <code>yy_c</code>. The position to lookup is generated by <code>YY_SC_TO_UI</code> and that's where I'm lost porting this to JavaScript. <code>YY_SC_TO_UI</code> has to return a number between 0-255, so do I just take what I have and:</p>
  
  <pre><code> "[c]".charCodeAt(0)
  </code></pre>
  
  <p>or are ia there anything else I need to be aware of handling "possible negative, possible signed char" in JS?</p>
  
  <p>Thanks.</p>