Home:ALL Converter>Different implementations of a C header file

Different implementations of a C header file

Ask Time:2010-12-08T13:17:06         Author:David Robles

Json Formatter

How can I add multiple implementations to this header file:

MoveAgent.h

#ifndef _GAMEAGENT_
#define _GAMEAGENT_

#include "Defs.h"
#include "GameModel.h"

MoveDirection takeDirection(GameState *gs);

#endif _GAMEAGENT_

MoveAgent.c: Let's say that I have an implementation that will return a random move

MoveDirection takeDirection(GameState *gs) {    
    MoveDirection dir = DIR_NONE;       
    while (dir == DIR_NONE) {
        int index = arc4random() % gs->moves_total;     
        MoveDirection tempDir = gs->moves[index];       
        if (tempDir != oppDir(gs->car.direction)) {
            dir = tempDir;
        }
    }
    return dir;
}

What is practical way of having multiple implementations of that function?

As you might guess, I'm a Java programmer trying to make a basic game to learn C, so I'm trying to do this to simulate a Java interface.

Any ideas?

Author:David Robles,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/4384405/different-implementations-of-a-c-header-file
yy