Question regarding void () in C.

This is a discussion on Question regarding void () in C. within the C Programming forums, part of the General Programming Boards category; Hello everyone. I'd like to get some help with this issue... I've got a program that consists in 1 initialization ...

  1. #1
    Registered User Pecado's Avatar
    Join Date
    Sep 2010
    Posts
    34

    Question Question regarding void () in C.

    Hello everyone. I'd like to get some help with this issue...

    I've got a program that consists in 1 initialization of a library and 2 voids, like this:
    Code:
    init_library()
    {
    ...
    first(); // Once it's initialized, it takes me to the loop of void first() in which I use the program.
    }
    void first()
    {
    ...
    if(a=1){void second(); second();} //Example. If a=1, the code loop of void second() starts happening.
    }
    
    void second()
    {
    ...
    if(a=2){void first(); first();} //Example. If a=2, the code loop of void first() starts happening.
    }
    And basically it jumps from void to void all the time, which works perfectly.

    My problem, however, is that in each void (first and second) I have to initialize hundreds of Bitmaps... and since I have to initialize the exact same ones both in void first and second, I thought it would be great to be able to initialize them all just once. (Also there are a lot of code lines that apply to both of the voids and that I'd like not to write them twice).

    But the program is reluctant to work unless the bitmaps are declared in each void they are used. So, if you followed me up to this point, what I tried to do is to "get the 2 voids inside one void" to initialize the bitmaps in that big void, though it won't let me.

    So, do you know of any way to work this out? Maybe using a .h or .rc? (tried but probably didn't link them right).

    Any help is appreciated, and if you need further info, let me know. Thanks.

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,703
    and since I have to initialize the exact same ones both in void first and second, I thought it would be great to be able to initialize them all just once. (Also there are a lot of code lines that apply to both of the voids and that I'd like not to write them twice).
    Refactor the common code into a new static function that first and second could call. The bitmaps will have to be passed back to first and second, unless they are global bitmaps. You can pass them back by return value or by an out-going parameter if you need to.

    void DoCommonThings( Bitmaps **loadme, size *arSize);

    Also, call functions by their name. Anything else is not distinct enough.

  3. #3
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    Y'know, I seen me a mermaid once. I even seen me a shark eat an octopus. But I ain't never seen nobody referring to "functions" as "voids" before.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #4
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,650
    Shows a pretty big lack of understanding I think. That or a big language barrier.

  5. #5
    Registered User Pecado's Avatar
    Join Date
    Sep 2010
    Posts
    34
    Hmm, probably the first option, language isn't a problem luckily.

    Anyways, yes I know the basics in C, that's why I was asking how to do this. Whiteflags answer was probably right but I don't know how to apply it xD.

    I've found an alternative way to solve my problem avoiding voids so thanks anyways. (Allthough if anyone is kind to give me any other solution, or explain it in more detail, I'll be checking the thread a few days more).

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Pecado View Post
    Hmm, probably the first option, language isn't a problem luckily.

    Anyways, yes I know the basics in C, that's why I was asking how to do this. Whiteflags answer was probably right but I don't know how to apply it xD.

    I've found an alternative way to solve my problem avoiding voids so thanks anyways. (Allthough if anyone is kind to give me any other solution, or explain it in more detail, I'll be checking the thread a few days more).
    FWIW... they weren't talking about not using "voids"... they were talking about your rather obvious confusion about what constitutes a function...

    Code:
    void second()
    First of all... void refers to the return value of the function you named second() ...
    Secondly it's ill formed... a function that returns nothing and takes no parameters is written as
    Code:
    void second ( void )
      {  // stuff   
       }
    Functions are good things... use them liberally! They encapsulate data and localize execution and thus provide powerful organizational tools in your programming. Basically they let you think in smaller blobs, only having to concern yourself with the immediate thing you are doing.

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    if(a=1){void second(); second();} //Example. If a=1, the code loop of void second() starts happening.
    }
    
    void second()
    {
    ...
    if(a=2){void first(); first();} //Example. If a=2, the code loop of void first() starts happening.
    }
    For starters, all of your if checks will end up as true, because you are using = (assignment) instead of == (test for equality).

    Next, you are providing a function prototype so that you can actually call the function. No magic is happening, you're just telling your program what to expect. You are effectively describing the tool you are about to use.

    Third, you are actually calling your function. (You are using the tool you just described.) Without that description, you couldn't use this tool (function), because the actual function itself doesn't exist yet when you try to use it.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inserting a swf file in a windows application
    By face_master in forum Windows Programming
    Replies: 12
    Last Post: 05-03-2009, 11:29 AM
  2. Case Statement
    By danlee58 in forum C Programming
    Replies: 16
    Last Post: 11-23-2008, 07:46 PM
  3. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  4. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM
  5. what does this warningmean???
    By kreyes in forum C Programming
    Replies: 5
    Last Post: 03-04-2002, 06:53 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21