Cleaning up my code.

This is a discussion on Cleaning up my code. within the C Programming forums, part of the General Programming Boards category; Hello, this is just me being a bit a perfectionist, but I was wondering if it's possible to make this ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    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
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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, 09: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, 11:02 PM
  4. Cleaning up my code
    By LiKWiD in forum C++ Programming
    Replies: 16
    Last Post: 07-07-2003, 09: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21