Skip to main content
gamedev.net
🔒 Locked

va_start question

Started by Stoic 1 reply 3.2k views
Original Post
Stoic
Stoic
Hi, I'm trying to create a simple Logging system, and the compiler doesn't seem to like va_start... Here's my source code, am I missing something stupid?

#include "Singleton.h"

#include <stdio.h>
#include <stdlib.h>
#include <string>


class Log: public Singleton<Log>
{
public:
    Log(): EngineLog(NULL), AppLog(NULL){}
    ~Log(){}

    void Init()
    {
        EngineLog = fopen("LOG/EngineLog.txt", "w");
        AppLog = fopen("LOG/AppLog.txt", "w");

        if (!EngineLog)
            printf("EngineLog not Opened! \n");

        if (!AppLog)
            printf("AppLog not Opened! \n");
    }

    void Shutdown()
    {
        if (EngineLog)
            fclose(EngineLog);
        if (AppLog)
            fclose(AppLog);
    }

    //Do a cheat to support the same interface as Printf
    //Note, this isn't safe from buffer overflows. Don't try 
    // to print arbitrary length strings in here.
    void WriteEngine(const char *msg, ...)
    {
       va_list args; 
       va_start(args,msg);

       char szBuf[1024];
       vsprintf(szBuf,msg,args);

       fprintf(EngineLog, "%s", szBuf);
    }

    //Same as above
    void WriteApp(const char *msg, ...)
    {
       va_list args; 
       va_start(args,msg);

       char szBuf[1024];
       vsprintf(szBuf,msg,args);

       fprintf(AppLog, "%s", szBuf);
    }

private:
    FILE *EngineLog;
    FILE *AppLog;

};


When I try to compile, I get ('va_start': identifier not found, even with argument-dependent lookup). Is there something else I need to include? It seems to be finding va_list alright, I would have figured it would find va_start if it found va_list.... Thanks for any help!
...
darookie
darookie
#include <stdarg.h>
CTar
CTar
va_start is in cstdarg, like Darookie said, va_list should be there too though. Anyway you seem to be using a mix of C and C++, which isn't legal. You should include cstdio, cstdlib and cstdarg instead of stdio.h, stdlib.h and stdarg.h. (I'm not going to talk about the C-style code, since it's legal C++, but not encouraged in C++)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.