PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, December 19, 2022

[FIXED] How to declare multiple register variables in one line in c?

 December 19, 2022     c, syntax     No comments   

Issue

I'm implementing destroy method for a linked list by keeping pointers to previous and current nodes. I'd like to declare them as register variables in a single line. Is it possible?

void list_destroy(list *ls) {
  // does this mean both prev and curr are register variables?
  register node *prev, *curr;
  
  for (prev = 0, curr = ls; curr != 0; curr = curr->next) {
    if (prev != 0)
      free(prev);
    prev = curr;
  }
  free(ls);
}

or

void list_destroy(list *ls) {
  node register *prev, *curr;
  
  for (prev = 0, curr = ls; curr != 0; curr = curr->next) {
    if (prev != 0)
      free(prev);
    prev = curr;
  }
  free(ls);
}

Solution

register is a storage class specifier, so it applies to all the declarators in the declaration. It applies to bit prev and curr in these examples.

Commonly, you put storage class specifiers first on the line (before any type specifiers) but that is not required. Storage class and type specifiers can be in any order (but all must be before the declarators and any pointers or qualifiers or other modifiers on the declarator)



Answered By - Chris Dodd
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing