No target arhitecture error

Started by
12 comments, last by Paradigm Shifter 10 years, 5 months ago

so Im trying to use the zeromemory macro,and i included windows.h,but i get that error.Ideeas?

Advertisement

Please post a minimal code example (including project settings) that replicates this error.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]


#include <Windows>
#include <XInput.h>


void GamePad::check_connection(){
	for(DWORD i = 0; i < XUSER_MAX_COUNT && controllerID == -1;i++){
		XINPUT_STATE state;
		ZeroMemory(&state, sizeof(XINPUT_STATE));
		if(XInputGetState(i,&state) == ERROR_SUCCESS)
			controllerID = i;
	}
}

i have no ideea what could cause this

There's a thread about it on MSDN here http://social.msdn.microsoft.com/Forums/vstudio/en-US/c88faa9b-3d66-4586-a2ec-6f1a6e34c882/win64-error-no-target-architecture?forum=vcgeneral but I couldn't see a definitive answer.

My solution would be this:


#include <Windows>
#include <XInput.h>


void GamePad::check_connection(){
	for(DWORD i = 0; i < XUSER_MAX_COUNT && controllerID == -1;i++){
		XINPUT_STATE state = {0}; // Does same thing as ZeroMemory
		//ZeroMemory(&state, sizeof(XINPUT_STATE));
		if(XInputGetState(i,&state) == ERROR_SUCCESS)
			controllerID = i;
	}
}

and let the compiler do it for you.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

Your solution worked,thanks.

I always use that method to zero out structs on the stack. Maybe ZeroMemory can be slightly more optimised, I dunno, but surely the compiler can optimise it anyway? You'd have to look at the assembly output to see if there are any differences.

The = {0} thing always works if the struct has no constructors defined and is portable, and doesn't rely on macros or function calls. The reason it works is that if you don't initialise all members of a struct (or array) (EDIT: but you do provide an initialiser for at least one field) the rest get zero initialised, so if you zero initialise the first member everything gets zeroed.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

I always use that method to zero out structs on the stack. Maybe ZeroMemory can be slightly more optimised, I dunno, but surely the compiler can optimise it anyway?

ZeroMemory is a macro that wraps memset.

{0} will try to call default constructors of the members. So the *code speed* depends on the structure.

Right I'd probably only recommend my way for POD structs then (which is basically everything in the Win32 API).

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
Non-POD structs and classes should have constructors anyway, so they should be designed to have initialized members on construction.

Not if you want your API to be compatible with C, which can be important. Win32 is all C anyway, even the COM (ActiveX) stuff has C bindings via macros.

You can use the preprocessor to exclude constructors and other C++ related stuff from C builds anyway.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

This topic is closed to new replies.

Advertisement