• C

Two ways of implementing a List

// 1. From Algorithms in C, Robert Sedgewick

List list;

// initialize the list
void init(&list)
     // initialization here

// 2. From The C Programming Language, Dennis Ritchie    <= we all know who he is

List* list;

// initialize the list
List* init()
     List* list;
     list = malloc(............................);
     return list;

I myself prefer the second way.

As consulted from my teacher, the first way has some security problems.
In 1., what is known to the main program is a whole list, and hackers may know very early the structure of a list only by looking at the main file.
In 2., what is known to the main program is only a pointer to a list, and it remains a pointer until the list is initialized. If hackers want to hack into the program by learning the structure of the list, he has to go deep into the implementation part.

Please give any comments you have on the differences between the 2 ways and their advantages / disadvantages.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

There are many ways to achieve hack-proof code. Designing your code with hackers in mind feels wrong to me.

Coding style is a cost/benefit tradeoff like any other commenrcial decision. This may be an old-codger attitude but evaluating the cost/benefit of coding in a more obscure fasion as a benefit goes against almost everything I believe in. An order of magnitude more time is spent enhancing your code than initially coding it. The priority MUST be to code for all the other programmers who need to work with your code.

My personal technique for linked lists looks like this:

typedef struct ListNode {
 struct ListNode* next;  
 struct ListNode* prev;
} ListNode;

typedef struct List {
 ListNode * head;
 ListNode * tail;

Then, use it like this:

typedef struct Thing {
 ListNode list1;
 ListNode list2;
 // Items.
} Thing;

List List1;
List List2;

Thing * newThing = (Thing *) malloc ( sizeof ( Thing ) );


ListAdd ( &newThing->list1, &List1 );
ListAdd ( &newThing->list2, &List2 );

The benefit of this technique is that you can add the same item to as many lists as you like and therefore sort items in multiple orders etc.

Let me know if any of this is unclear and I'll expand.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kent OlsenDBACommented:
Hi PaulCaswell,

Here, Here!  Amen Paul!

Hi DacTin,

If obfuscation within the object module is a critical part of your requirements, write in a language that adds its own layers of hard-to-trace "stuff".  Like C++.

Anyone that deliberately writes bad or obscure code to make the object code tougher to crack should be shot.  period.

Good Luck!
When writing code the objective should be

  - correct execution
  - maintainable (readable) code
  - documented code

most code should not be concerned with attcks. This is a separate domain. Also then the security and safety should be in the desingn and not through an unreadable imlementation.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.