Check if function argument is a string

How do I check if an arg extracted from va_arg inside a function is a string?

My function has variable number of args.
Last edited on
You can't. Use variadic function templates instead.
You appear to be trying to force the language/preprocessor system into doing something it wasn't designed to do. While you might be able to use variadic function templates, this inevitably adds complexity that perhaps you don't need.

If you explained the end goal of what you are trying to do, somebody might be able to offer a better design.
You have to know the type of every specified variadic function argument. That's why with printf() et al (which uses variadic functions) you have to specify exactly the type of each argument in the format string.
Off the top of my head.....

Are you trying to do this check at compile time or runtime? That does make a difference.

With C it ain't possible -- maybe, possibly with a lot of code that makes for overly complex and hard-to-maintain code.

C++ is (probably) able to do what is wanted, using templates and/or concepts. The level of complexity is less, but still a nightmare.

I just spitballing SWAG since I have never tried to rewrite the language to such a degree as you continue to want.
You can do that when you use the type/value paradigm.

For instance by prefixing any value with one byte that determines the type. The value 0 might determine the end of the list.

Thanks for the input guys. I'm not really leaning into using variadic macros for this one.


@coder777

Yes, you might be into something there and I did think about this one before.
Topic archived. No new replies allowed.