Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dbg_printf should not take a buffer argument. #13

Closed
elfprince13 opened this issue Feb 6, 2016 · 6 comments
Closed

dbg_printf should not take a buffer argument. #13

elfprince13 opened this issue Feb 6, 2016 · 6 comments

Comments

@elfprince13
Copy link
Contributor

It would be more useful to have dbg_printf be an actual function, mimicking printf usage. Keep dbgout as a global variable, and provide a definition that sprintfs to dbgout.

@elfprince13
Copy link
Contributor Author

Suggested implementation:

int dbg_printf(const char* fmt, ...){
    va_list args;
    va_start(args, fmt);
    vsprintf(dbgout, fmt, args);
    va_end(args);
}

@mateoconlechuga
Copy link
Member

mateoconlechuga commented Feb 6, 2016 via email

@mateoconlechuga
Copy link
Member

Actually, I prefer to leave the dbg_printf this way. That way you can write output elsewhere or something rather than to the console. This is one extra argument; it's not that bad :P

@elfprince13
Copy link
Contributor Author

The problem is that I'm trying to maintain API-coherence with the PC version of my code base, and C89 doesn't support variadic macros, so I currently have to have #define dPrintf(args) printf args, but there's no way that I know of to unpack the args paren-expression to insert the dbgout reference.

@adriweb
Copy link
Member

adriweb commented Feb 6, 2016

@elfprince13: Making a wrapper function that calls the actual one with the argument(s) already setup (dbgout etc.) should do the trick?

@mateoconlechuga
Copy link
Member

void dPrintf(const char* fmt, ...){
    va_list args;
    va_start(args, fmt);
    vsprintf(dbgout, fmt, args);
    va_end(args);
}

Works well with v1.6

Please note that this code increases the outputted binary by 8105 bytes though. This is pretty substantial when you only have 64kb to work with. I would recommend you change the computer side API, but that's entirely up to you as that would be some work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants