Why (void) at the start of an expression?

Hi,

I have this code:

1
2
3
4
5
6
7
	static void _(Types... t)
	{
		using swallow = int[];
		(void) 	swallow {
			(process(t),0)...
		};
        }


What does (void) do? Why is it required? Is it required?
MSVC compiler emits no warning if I remove it....

Also, why does replacing swallow with int[] gives a compiler error? Aren't the 2 the same type (i.e. swallow is int[])?

1
2
3
4
		(void) 	int[] {
			(process(t),0)...
		};


Thanks
Juan
Casting to void is used to signal that the author knows there is an "unused" value or variable (useful if there is a lint-like tool somewhere in the tool-chain.)

As for the other, MSVC doesn't fully support compound literals so the using directive is probably a work around for that (I'm not entirely sure what the C++ standard says about compound literals - most things I found when searching referenced the C99 standard.) If it did support it, the syntax would be a bit off. See: http://en.cppreference.com/w/c/language/compound_literal

Useful link for anyone curious about what's going on here:
https://stackoverflow.com/a/25683817
Registered users can post here. Sign in or register to post.