Login Register






Tutorial [C] Type Ambiguous Stack filter_list
Author
Message
RE: [C] Type Ambiguous Stack #5
(01-03-2015, 05:37 PM)0xDEAD10CC Wrote: The other thing you could do if you wanted actual stack types, is define whichever ones you want, using macros:
Code:
/* * Author: 0xDEAD10CC * Date: 2015-01-01 16:04:36 * Filename: main.c * Last Modified time: 2015-01-03 09:37:35 */ #include <stdio.h> #include <stdlib.h> #define def_stack_t(T) \ struct stack_t_##T \ { \ T *p_base; \ T *data; \ }; #define stack_t(T) struct stack_t_##T def_stack_t(int) def_stack_t(float) int main(void) { stack_t(int) *stack_obj = ...; // deal with stack object here free(stack_obj); }

Now you can define generic stack functions that work with void *, or you can create an army of macros to do all of the calculations for the sizes for you too.

That is a way to do a "template" stack in C, but not a real stack. Since you are only able to put integers on that stack.

Reply





Messages In This Thread
[C] Type Ambiguous Stack - by phyrrus9 - 12-31-2014, 09:05 AM
RE: [C] Type Ambiguous Stack - by 0xDEAD10CC - 01-01-2015, 11:35 PM
RE: [C] Type Ambiguous Stack - by phyrrus9 - 01-02-2015, 10:05 PM
RE: [C] Type Ambiguous Stack - by 0xDEAD10CC - 01-03-2015, 05:37 PM
RE: [C] Type Ambiguous Stack - by phyrrus9 - 01-03-2015, 05:48 PM
RE: [C] Type Ambiguous Stack - by 0xDEAD10CC - 01-03-2015, 06:26 PM
RE: [C] Type Ambiguous Stack - by phyrrus9 - 01-03-2015, 06:28 PM
RE: [C] Type Ambiguous Stack - by 0xDEAD10CC - 01-03-2015, 06:34 PM
RE: [C] Type Ambiguous Stack - by phyrrus9 - 01-03-2015, 06:35 PM
RE: [C] Type Ambiguous Stack - by 0xDEAD10CC - 01-03-2015, 07:06 PM
RE: [C] Type Ambiguous Stack - by phyrrus9 - 01-03-2015, 07:07 PM