Skip to main content

Timeline for Generic stack in C

Current License: CC BY-SA 3.0

9 events
when toggle format what by license comment
Jul 10, 2015 at 13:51 comment added Edward @Lundin: when they're both in the same file, as in this program, it makes no difference. You seem to assume that an opaque type was a design goal. It's one way to implement, but not the only way or neccesarily the best way.
Jul 10, 2015 at 13:42 comment added Lundin @Edward Of course it does, there must be one declaration of incomplete type visible to the caller and the struct definition of that type, which is not visible to the caller. Why would you have the typedef at the struct definition rather than at the incomplete type declaration? That doesn't make any sense.
Jul 10, 2015 at 13:36 comment added Edward @Lundin: whether the typedef and struct declaration are on the same line or two different ones has no bearing on whether it's an opaque type or not.
Jul 10, 2015 at 13:28 comment added Lundin "Combine typedef and structure declaration" this is bad advise and suggests that you don't know the meaning of opaque type. I would remove this part of your otherwise good answer, as it is incorrect in the context of creating an opaque type ADT. "Consider object ownership" is related to this: the ADT allocates the objects, since it is impossible for the caller to do so: it cannot create an instance of an incomplete type!
Jul 9, 2015 at 15:34 comment added lord.garbage What I basically did was to implement a create() and destroy() function: pstack create(void) {pstack s = malloc(sizeof(struct Stack)); if (!s) {exit(EXIT_FAILURE)}; s->next = NULL; return s;} and void destroy(pstack s) {free(s);};. Thanks for your help!
Jul 9, 2015 at 15:27 vote accept lord.garbage
Jul 9, 2015 at 15:19 comment added Edward Yes, set s1 = NULL at the beginning and also change to bool is_empty(pstack *s) { return s != NULL; }
Jul 9, 2015 at 15:05 comment added lord.garbage Thanks! Where should I set the value to 0? Do you mean when I declare pstack s1 in main() by setting s1 = NULL at the beginning?
Jul 9, 2015 at 14:50 history answered Edward CC BY-SA 3.0