absyntax_utils/get_sizeof_datatype.cc
changeset 306 82c1f453cd07
parent 304 1b6d8e3df1b2
child 417 d48f53715f77
equal deleted inserted replaced
305:fe5cb87610fa 306:82c1f453cd07
   217    * determine the the bitsize using integer aritmetic.
   217    * determine the the bitsize using integer aritmetic.
   218    * However, we are then limited to the bit size of the widest available integer
   218    * However, we are then limited to the bit size of the widest available integer
   219    * (usually 64 bits), which is not good at all!
   219    * (usually 64 bits), which is not good at all!
   220    */
   220    */
   221   /* Let's try to determine bitsize by converting directly from the string!! */
   221   /* Let's try to determine bitsize by converting directly from the string!! */
       
   222   char *sval, *oval;
       
   223   const char *pval;
       
   224   oval = sval = (char *)malloc(strlen(symbol->value)+1);
       
   225   if (NULL ==  sval) ERROR;
       
   226 
       
   227   /* copy the original string, but leave out any underscores... */
       
   228   for (pval = symbol->value, sval = oval; *pval != '\0'; pval++) {
       
   229     if ('_' != *pval) {*sval = *pval; sval++;}
       
   230   }  
       
   231   *sval = '\0';  
       
   232   
       
   233   sval = oval;
       
   234   if ('\0' == *sval) ERROR;
       
   235 
       
   236   for (bitsize = 0; *sval != '\0'; strdivby2(&sval), bitsize ++);
       
   237 
       
   238 /*
   222   char *sval = strdup(symbol->value);
   239   char *sval = strdup(symbol->value);
   223   char *oval = sval;
   240   char *oval = sval;
   224   if (NULL ==  sval) ERROR;
   241   if (NULL ==  sval) ERROR;
   225   if ('\0' == *sval) ERROR;
   242   if ('\0' == *sval) ERROR;
   226 
       
   227   for (bitsize = 0; *sval != '\0'; strdivby2(&sval), bitsize ++);
   243   for (bitsize = 0; *sval != '\0'; strdivby2(&sval), bitsize ++);
       
   244 */
   228 
   245 
   229   /* Even for (value == 0), the above loop will return bitsize == 1!, 
   246   /* Even for (value == 0), the above loop will return bitsize == 1!, 
   230    * so we don't need to handle the special case...
   247    * so we don't need to handle the special case...
   231    */
   248    */
   232   /* special case... if (value == 0) <=> (bitsize == 0), return bit size of 1 ! */
   249   /* special case... if (value == 0) <=> (bitsize == 0), return bit size of 1 ! */