Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Advice on linked list

Name: Anonymous 2010-02-24 22:19

Hello all, I am creating a program which has a linked list. The linked list contains 2 different structs: variable, and function. For a while I was connecting the lists by using void pointers and using casts to get their data, e.g.: void *previous, *next;
((struct variable *)temp->previous)
.
Basically, I am placing functions in the same list as variables and vice-versa. I was wondering, would it be better to just place them in separate lists? Is it not worth the trouble to do it my way?

Name: Anonymous 2010-02-25 1:32

lrn2union

Name: Anonymous 2010-02-25 1:38

Basically, I am placing functions in the same list as variables and vice-versa
DESIGN PATTERNS MY ANUS

Name: Anonymous 2010-02-25 1:42

>>1
Depends what the data is. When you store both, how do you know whether the next item is a function or variable?

Anyways if you do want to store both together you should do inheritance/polymorphism properly. The way you're doing it now is a violation of strict aliasing. Assuming you have some external way of determining whether the next link is a variable or function:

struct link {
  struct link *previous, *next;
};

struct variable {
  struct link;
  // some shit
};

struct function {
  struct link;
  // some other shit
};


Just make sure link is the first field. Now you can cast both function and variable to link and vice versa; it's an exception to the aliasing rules since (&some_func == &some_func.link).

Name: Anonymous 2010-02-25 1:48

>>2
union is poor man's polymorphism. It's a shitty hack that has few reasons to exist.

Name: Anonymous 2010-02-25 4:33

>>5
Lincoln didn't think the union was ``a shitty hack''.

Name: Anonymous 2010-02-25 14:02

>>6
2/10
Actually I'm just mad because I didn't think of it first.

Name: Anonymous 2010-02-25 14:18

>>6

Lincoln was a hack

Name: Anonymous 2010-02-25 15:11

Lincoln got haxed

Name: Anonymous 2010-02-25 15:13


          ,---,
          |   |    John Wilkes Booth HAXED MY ANUS
          |   |   /
          |___|
         _|___|_
        [_______]
         \|. .|/
         (| > |)
         _\`-'/_
       /`  \_/  `\

Name: Anonymous 2010-02-25 16:01

>>6
ya but when pelosi and her liberal friends are done all thats let will be a shitty hack

Name: Anonymous 2010-02-25 16:07

>>11
You're on the wrong board. /newpol/ is that^ way.

Name: Anonymous 2010-02-25 17:53

>>11
I love how Americans think that the "Democrats" are "liberal"

Name: Anonymous 2010-02-25 19:16

>>13
"I" "love" "how" ">>11" "makes" "liberal" "use" "of" "proper" "quotes""."

Name: Anonymous 2010-02-25 21:11

>>13
I love how people think that the word "liberal" is well defined in any way

Name: Anonymous 2010-02-25 22:32

>>8
Lincoln hacked a cherry tree.

Name: Anonymous 2010-02-26 4:05

>>15
s/people/"people"/

Name: Anonymous 2010-02-26 12:46

>>16
HAX MY CHERRY

Name: Anonymous 2010-02-26 15:16

I like unions. Why would anyone complain about them?

Name: Anonymous 2010-02-26 16:07

did you say a list? I heard there's this language, called LISP, I think it's real good at lists.

Name: Anonymous 2010-02-26 16:08

>>20
It's terrible with lists, but is really good with vectors. Perhaps you were thinking of APL?

Name: Anonymous 2010-02-26 16:09

>>20
I find it's much more convenient to implement an ad hoc, informally-specified, bug-ridden, slow implementation of half of Lisp, than to actually use Lisp

Name: Anonymous 2010-02-26 18:40

>>19
They don't understand them.

Name: Anonymous 2010-02-26 21:54

>>23
They should stop saying yoon-yun and start saying un-yun.

Name: Anonymous 2010-02-26 22:22

Singly linked lists are always the wrong data structure. There is no possible justifiable use case for them.

Name: Anonymous 2010-02-26 22:29

>>25
Really, Christopher?

Name: Anonymous 2010-02-26 22:32

>>26
I think that's slava

Name: Anonymous 2010-02-26 23:21

>>27
slava visits the /prague/?

Name: Anonymous 2010-02-27 0:51

>>25
Didn't we already have that thread?
http://dis.4chan.org/read/prog/1255221974

Name: Anonymous 2011-01-31 20:23

<-- check em dubz

Don't change these.
Name: Email:
Entire Thread Thread List