Outputting a string to STDOUT with our libc functions

R

raashid bhatt

how to print something with out calling libc functions like printf ,
puts etc..

This is the direct method how libc printf works on windows
so why not use this one and get rid of MSVCRT.DLL linking
but make suer to link it with kernel32.lib

#include <windows.h>

int __stdcall main(int argc, char **argv)
{
HANDLE handle;
handle = GetStdHandle(STD_OUTPUT_HANDLE);

WriteFile(handle, "hello world!", 12, NULL, NULL);
CloseHandle(handle);
return 0;
}

link /ENTRY:main program.obj kernel32.lib
 
A

Andrew Poelstra

how to print something with out calling libc functions like printf ,
puts etc..

This is the direct method how libc printf works on windows
so why not use this one and get rid of MSVCRT.DLL linking
but make suer to link it with kernel32.lib

#include <windows.h>

int __stdcall main(int argc, char **argv)
{
HANDLE handle;
handle = GetStdHandle(STD_OUTPUT_HANDLE);

WriteFile(handle, "hello world!", 12, NULL, NULL);
CloseHandle(handle);
return 0;
}

Because that will work on Windows and only Windows.

puts("Hello, world!")

will work on *all* platforms supporting C. (Excepting C99 'freestanding'
compilers, which generally are only used for small embedded platforms.
 
S

santosh

raashid said:
how to print something with out calling libc functions like printf ,
puts etc..

This is the direct method how libc printf works on windows
so why not use this one and get rid of MSVCRT.DLL linking
but make suer to link it with kernel32.lib

#include <windows.h>

int __stdcall main(int argc, char **argv)
{
HANDLE handle;
handle = GetStdHandle(STD_OUTPUT_HANDLE);

WriteFile(handle, "hello world!", 12, NULL, NULL);
CloseHandle(handle);
return 0;
}

link /ENTRY:main program.obj kernel32.lib

This will tie your code to the Windows API while using puts will mean
that your program can run wherever a conforming ISO C implementation is
available, which is far more widespread than implementations of the
Windows API.
 
K

Keith Thompson

Andrew Poelstra said:
puts("Hello, world!")

will work on *all* platforms supporting C. (Excepting C99 'freestanding'
compilers, which generally are only used for small embedded platforms.

Or C90 freestanding implementations; the distinction between
freestanding and hosted implementations isn't new in C99.
 
G

gw7rib

how to print something with out calling libc functions like printf ,
puts etc..

This is the direct method how libc printf works on windows
so why not use this one and get rid of MSVCRT.DLL linking
but make suer to link it with kernel32.lib

#include <windows.h>

int __stdcall main(int argc, char **argv)
{
    HANDLE handle;
    handle = GetStdHandle(STD_OUTPUT_HANDLE);

    WriteFile(handle, "hello world!", 12, NULL, NULL);
    CloseHandle(handle);
    return 0;

}

link /ENTRY:main program.obj kernel32.lib

Of course, printf can also do formatting - that's what the "f" stands
for.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top