Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-27-2003, 04:53 PM   #1
Registered: Sep 2003
Posts: 104

Rep: Reputation: 20
free()'n args

I'm not sure if it is possible, but I want to make a function called freeAll (hopefully that is self explanitory) using a va_list, I'm not sure if this is possible, could someone help me out on this, anyway.. my reasoning is I have about 7, or 8.. variables malloc'd, and when an error occurs I have to free them all, but I think it would be easier if I could just do something like ->

freeAll(malloc_one, malloc_two, malloc_three, ...) then having to do ->


I know I should've searched a little longer, and probably hunted the forums, but it's hard to phrase this in a search engine..
Old 10-27-2003, 05:02 PM   #2
jim mcnamara
Registered: May 2002
Posts: 964

Rep: Reputation: 36
void freeAll(void **ptr, int count){
     int i=0;
Old 10-27-2003, 05:07 PM   #3
Registered: Sep 2003
Posts: 104

Original Poster
Rep: Reputation: 20
multi-demensional array? hmm, that could work, but I meant passing each variable.. something like:

void freeAll(int c, void *q, ...)
    va_args args;
    int j;

    va_start(args, q);
    for(j = 0; j < c; ++j)
        free(va_arg(args, char*));

Last edited by zer0python; 10-27-2003 at 05:12 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
processing command args in bash slzckboy Programming 16 10-18-2017 03:12 AM
command line args in a countdown Squeak2704 Programming 1 04-26-2004 12:27 PM
Ant & args for java acjt Programming 1 04-25-2004 12:01 AM
Bash script; command and args in variable. magjo813 Programming 2 02-16-2004 09:22 AM
>>> control mplayer with command args??? nibjb Linux - Software 0 07-16-2003 11:09 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:58 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration