User talk:MicheleN

From Sistemi Operativi
Revision as of 09:31, 17 October 2016 by Renzo (talk | contribs) (Created page with "Caro MicheleN, perchè vuoi porre cmpvalue=1? è inutile. <syntaxhighlight lang=C> struct word *addword(char *word, struct word *wlist) { struct word **scan; ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Caro MicheleN,

perchè vuoi porre cmpvalue=1?

è inutile.

struct word *addword(char *word, struct word *wlist) {
  struct word **scan;
  int cmpvalue /* = 1 useless */;
  for (scan = &wlist;
      *scan != NULL && ((cmpvalue = lenalphacmp(word, (*scan)->word)) > 0);
      scan = &((*scan)->next))
    ;
  if (scan != NULL && cmpvalue == 0)
    (*scan)->count ++;
  else {
    struct word *new = malloc(sizeof(struct word) + strlen(word) + 1);
    if (new) {
      new->next = *scan;
      new->count = 1;
      strcpy(new->word, word);
      *scan = new;
    }
  }
  return wlist;
}

Se scan è NULL esce subito dal ciclo e cmpvalue ha un valore indefinito, ma cmpvalue non viene valutato nell'if che segue (per cortocircuitazione dell'&&). Se scan non &egrave NULL, cmpvalue viene assegnato. no?

Renzo (talk) 10:31, 17 October 2016 (CEST)