Jump to content
  • Advertisement
Sign in to follow this  
Stoic

va_start question

This topic is 4404 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Advertisement
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++)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!