Thread: Cleaning up my code.

  1. #1
    Registered User
    Join Date
    Jul 2013
    Posts
    8

    Angry Cleaning up my code.

    Hello, this is just me being a bit a perfectionist, but I was wondering if it's possible to make this snippet of code shorter and perhaps more efficient.
    Code:
    p_sstack->data[p_sstack->size - 1].data[p_sstack->data[p_sstack->size - 1].size - 1].symtype = p_newsym->symtype;p_sstack->data[p_sstack->size - 1].data[p_sstack->data[p_sstack->size - 1].size - 1].identifier = p_newsym->identifier;p_sstack->data[p_sstack->size - 1].data[p_sstack->data[p_sstack->size - 1].size - 1].data = p_newsym->data;p_sstack->data[p_sstack->size - 1].data[p_sstack->data[p_sstack->size - 1].size - 1].immutable = p_newsym->immutable;
    p_sstack is a parameter of type sstack*, which is a struct containing members int size and slist* data. slist is a struct containing members int size and sym* data. sym is a struct containing members symtype* type, char* identifier, void* data and bool immutable. p_newsym is a parameter of type sym*.

  2. #2
    Registered User
    Join Date
    Jul 2013
    Posts
    8
    P.S, I toughly apologize for the awful formatting of the code, it seemed to ignore all of my new-lines.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    in my opinion - you do not need to make it shorter. you need to make it easier to follow.

    Code:
    data* tail        = &p_sstack->data[p_sstack->size - 1];
    data* tails_tail = &tail->data[tail->size - 1];
    
    etc
    with some self describing variable names
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #4
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    You can do this:
    Code:
    i = p_sstack->size - 1;
    j = p_sstack->data[i].size - 1;
    p_sstack->data[i].data[j] = p_newsym;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linklist cleaning HELP
    By killmequick in forum C Programming
    Replies: 0
    Last Post: 10-28-2008, 08:11 AM
  2. Cleaning up array code
    By Zimmer in forum C++ Programming
    Replies: 5
    Last Post: 11-16-2005, 07:27 PM
  3. Cleaning listbox
    By publikum in forum Windows Programming
    Replies: 4
    Last Post: 04-08-2005, 10:02 PM
  4. Cleaning up my code
    By LiKWiD in forum C++ Programming
    Replies: 16
    Last Post: 07-07-2003, 08:52 PM
  5. need some help cleaning code up
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 03-03-2002, 07:28 AM