Login Register






Simple Shell Program filter_list
Author
Message
RE: Simple Shell Program #11
You don't need '&' before the function name in your function pointer array because they will decay to the appropriate pointer types.

But why do you free args twice here?
Code:
do { printf("%c%s%c%c ", '$', login, '_', '>'); args = getArgs(&args_size); status = execute(args); free_a(args, args_size); free(args); } while (status); free_a(args, args_size); free(args); free(login);

There's not much reason to be using the heap here either way for those allocations that stay within main. sizeof(char) is guaranteed to be 1 too, and why not use a macro if you're going to use sizeof() operator to check the size of things? More efficient than using a function that you haven't even marked as inline (sizeof is a compile-time operator that you place within a runtime function, and you can't guarantee that it'll be inlined unless compiler optimization is enabled and deals with that for you):

Code:
int num_builtins() { return sizeof(builtin_str) / sizeof(char *); }

sizeof() returns size_t though; you could have done:
Code:
size_t num_builtins() { return sizeof(builtin_str) / sizeof(*builtin_str); }

Or a generic macro:
Code:
#define SIZEOFA(arr) (sizeof(arr) / sizeof(*arr))

Lots of other performance improvements can be made.
(This post was last modified: 11-30-2016, 08:15 AM by bitm0de.)
- mostly braindead monkeys on this forum.

[+] 2 users Like bitm0de's post
Reply





Messages In This Thread
Simple Shell Program - by insidious - 10-16-2016, 04:22 AM
RE: Simple Shell Program - by phyrrus9 - 10-16-2016, 07:42 AM
RE: Simple Shell Program - by Inori - 10-17-2016, 11:58 PM
RE: Simple Shell Program - by phyrrus9 - 10-18-2016, 12:24 AM
RE: Simple Shell Program - by Inori - 10-18-2016, 12:25 AM
RE: Simple Shell Program - by phyrrus9 - 10-18-2016, 12:36 AM
RE: Simple Shell Program - by insidious - 10-18-2016, 05:44 AM
RE: Simple Shell Program - by phyrrus9 - 10-18-2016, 05:46 AM
RE: Simple Shell Program - by insidious - 10-18-2016, 05:51 AM
RE: Simple Shell Program - by phyrrus9 - 10-18-2016, 05:54 AM
RE: Simple Shell Program - by bitm0de - 11-30-2016, 08:02 AM
RE: Simple Shell Program - by insidious - 11-30-2016, 05:14 PM
RE: Simple Shell Program - by bitm0de - 11-30-2016, 06:13 PM