From: Alex Blekhman on
"Vincent Fatica" wrote:
> (VC9) I am trying to avoid the runtime library in a tiny app
> (something I do regularly). When I try to zero-fill a
> STARTUPINFO struct with a for-loop, the compiler turns my
> for-loop into a call to _memset.
> [...]
> How do I avoid that (elegantly)? Is it some kind of
> optimization I can simply turn off?

I noticed that optimize for size (/O1) triggers the compiler to
embed calls to memset. #pragma intrinsic(memset) has no any effect
on this behavior. You can still leave optimize for speed (/O2)
though. Also, do not set full optimization (/Ox).

HTH
Alex

From: Vincent Fatica on
On Sun, 6 Sep 2009 22:02:13 +0300, "Alex Blekhman" <tkfx.REMOVE(a)yahoo.com>
wrote:

|"Vincent Fatica" wrote:
|> (VC9) I am trying to avoid the runtime library in a tiny app
|> (something I do regularly). When I try to zero-fill a
|> STARTUPINFO struct with a for-loop, the compiler turns my
|> for-loop into a call to _memset.
|> [...]
|> How do I avoid that (elegantly)? Is it some kind of
|> optimization I can simply turn off?
|
|I noticed that optimize for size (/O1) triggers the compiler to
|embed calls to memset. #pragma intrinsic(memset) has no any effect
|on this behavior. You can still leave optimize for speed (/O2)
|though. Also, do not set full optimization (/Ox).

That's what I'm doing. But I get "warning LNK4210: .CRT section exists;"
--
- Vince
From: Alex Blekhman on
"Vincent Fatica" wrote:
> But I get "warning LNK4210: .CRT section exists;"

According to MSDN you have some static/global code that requires
CRT while it isn't available. Also, security checks (/GS) are
tightly integrated with the CRT, so you need to ensure that /GS is
not set for your project. I assume you already found this article:

KB814472 - "You receive linker warnings when you build Managed
Extensions for C++ DLL projects"
http://support.microsoft.com/kb/814472

It talks about managed code mostly, but can give you some insight
about what goes on.

HTH
Alex

From: Vincent Fatica on
On Sun, 6 Sep 2009 22:34:27 +0300, "Alex Blekhman" <tkfx.REMOVE(a)yahoo.com>
wrote:

|KB814472 - "You receive linker warnings when you build Managed
|Extensions for C++ DLL projects"
|http://support.microsoft.com/kb/814472

I've seen that before. Mine is an utterly simple program (below). Without
going out of my way at all, I apparently get the intrinsic wcslen() (no library,
no warming, no .CRT section). memset() is another story!

#include <windows.h>
#include <intrin.h>

INT MyWinMain(VOID)
{
WCHAR *pCmdLine = GetCommandLine();
INT argc;
WCHAR **argv = CommandLineToArgvW(pCmdLine, &argc);
pCmdLine += wcslen(argv[0]);
while ( *pCmdLine && *pCmdLine != L' ' )
pCmdLine += 1;
pCmdLine += 1;
STARTUPINFO si;
__stosb((UCHAR*) &si, 0, sizeof(si));
si.cb = sizeof(si);
PROCESS_INFORMATION pi;
CreateProcess(NULL, pCmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
LocalFree(argv);
return 0;
}
--
- Vince
From: xiaosi on
The titles of msdn are some misleading, while intrin.h is more truthful:
** __MACHINEI : Intel (32 bit x86) and X64
__MACHINEI(void __stosb(unsigned char *, unsigned char, size_t))

"Vincent Fatica" <vince(a)blackholespam.net> wrote:
> On Mon, 7 Sep 2009 00:56:43 +0800, "xiaosi" <xiaosi(a)cn99.com> wrote:
>
> |You may use intrinsic __stosb to replace memset:
> |#include <intrin.h>
> | STARTUPINFO si;
> | __stosb((unsigned char*)&si, 0, sizeof(si));
> | si.cb = sizeof(si);
>
> Thanks. That's interesting. There's something I wonder about. __stosb is
> listed in the documentation's "x64 Intrinsics"; it is not listed in "x86
> Intrinsics". What's up with that?
> --
> - Vince