December 01, 2002 Re: Stupid question | ||||
---|---|---|---|---|
| ||||
Posted in reply to anderson | Because I haven't written the code to do that <g>. "anderson" <anderson@firestar.com.au> wrote in message news:asca6p$dn0$1@digitaldaemon.com... > How come the gc can't be automaticly stated up in WinMain by the D compiler? > > "Walter" <walter@digitalmars.com> wrote in message news:asc945$bsk$2@digitaldaemon.com... > > The first thing I notice is the gc isn't being started up and shutdown in > > WinMain(). Check out the example in www.digitalmars.com/index.html under > "D > > for Win32" and "Windows Executables." > > > > "Karl Bochert" <kbochert@copper.net> wrote in message news:1103_1038703271@bose... > > > On Sat, 30 Nov 2002 15:23:09 -0800, "Walter" <walter@digitalmars.com> > > wrote: > > > > Please post a complete program that fails, that makes it a lot easier > > for > > > > us. > > > > > > > > > > Just read my own post. > > > Here's a version without the tabs. > > > > > > import windows; > > > import c.stdio; > > > import string; > > > > > > extern (Windows) { > > > int AllocConsole (); > > > }; > > > > > > HANDLE STDERR; > > > > > > static void show_console() > > > /* set up a console window if not done yet */ > > > { > > > > > > AllocConsole(); > > > // Must AllocConsole beore getting standard handles!! > > > STDERR = CreateFileA("CONOUT$", > > > GENERIC_READ | GENERIC_WRITE, > > > FILE_SHARE_WRITE, > > > (SECURITY_ATTRIBUTES*) 0,// Security not > > inherited > > > 0, > > > OPEN_EXISTING, > > > (HANDLE)0); > > > } > > > > > > > > > char[] foo () > > > { > > > char[] x ; > > > char[6] buf = "abcd"; > > > // uint i; > > > > > > > > > // x.length = 6; > > > // for (i = 0; i < 6; ++i) { > > > // x[i] = buf[i]; > > > // } > > > > > > x = buf.dup; > > > > > > return x; > > > } > > > > > > void Fputs(HANDLE fd, char[] out_string) > > > { > > > uint len; > > > > > > len = out_string.length; > > > WriteFile(fd, // handle to file > > > out_string, // data buffer > > > len, // number of bytes to write > > > &len, // number of bytes written > > > (OVERLAPPED*) 0 // overlapped buffer > > > ); > > > } > > > > > > > > > //HINSTANCE winInstance; > > > extern (Windows) > > > int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, > > > LPSTR szCmdLine, int iCmdShow) > > > { > > > int argc; > > > char **argv; > > > show_console(); > > > char[] line; > > > > > > Fputs (STDERR, "Hello"); > > > line = foo(); > > > // while(1) {}; > > > Fputs (STDERR, "Hello"); > > > > > > while(1){}; // Hang the console open > > > return 0; > > > } > > > > > > > > > > > > > > > |
December 01, 2002 Re: Stupid question | ||||
---|---|---|---|---|
| ||||
Posted in reply to anderson | Why are you using WinMain anyway? There's nothing there that can't be gotten later by other means. (GetModuleHandle etc.) Just use main(). Sean "anderson" <anderson@firestar.com.au> wrote in message news:asca6p$dn0$1@digitaldaemon.com... > How come the gc can't be automaticly stated up in WinMain by the D compiler? > > "Walter" <walter@digitalmars.com> wrote in message news:asc945$bsk$2@digitaldaemon.com... > > The first thing I notice is the gc isn't being started up and shutdown in > > WinMain(). Check out the example in www.digitalmars.com/index.html under > "D > > for Win32" and "Windows Executables." |
December 01, 2002 Re: Stupid question | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | On Sat, 30 Nov 2002 20:47:27 -0800, "Walter" <walter@digitalmars.com> wrote:
> Thanks, I'll check it out. -Walter
>
One of my earlier posts (# 9635 -- 113 lines) -showed 8 different ways
of returning the char[]. Can you tell me which are supposed to work?
A large portion of my problem is that I can't tell a bug from
my mis-understanding.
Here are a few further simplifications of the 'foo()' function
in my previous example
//calling this is ok
void foo ()
{
char[80] buf;
}
..
foo ()
//
//calling this fails
void foo ()
{
char[80] buf = "abcd"; // init a [N]
}
//OK
char[] x = "1234567890";
void foo ()
{
char[80] buf = "abcd";
uint i;
for (i = 0; i < 4; ++i) {
buf[i] = 'x';
}
x.length = 4;
for (i = 0; i < 4; ++i) {
x[i] = buf[i];
}
}
//fails
char[] x;
void foo ()
{
char[80] buf;
uint i;
for (i = 0; i < 4; ++i) {
buf[i] = 'x';
}
x.length = 4; // enlarge a []
for (i = 0; i < 4; ++i) {
x[i] = buf[i];
}
}
//fails
char[] x = "1234567890";
void foo ()
{
char[80] buf = "abcd";
uint i;
for (i = 0; i < 4; ++i) {
buf[i] = 'x';
}
x = buf.dup; // use dup
}
|
December 01, 2002 Re: Stupid question | ||||
---|---|---|---|---|
| ||||
Posted in reply to Karl Bochert | "Karl Bochert" <kbochert@copper.net> wrote in message news:1104_1038693845@bose... > The relevant code looks something like: > > char[] foo() // With an assortment of things I have tried > { > char[] x; > char[128] buf = "qwerty"; > > // modify buf ok? > strcpy (buf, "A test"); > > // should all of these return the same thing? > // -- they all fail -- > //1 > x = buf[0..3]; > return x; Will fail because you're pointing into the stack of a returned function. > //2 > return buf[0..3]; Will fail because you're pointing into the stack of a returned function. > > //3 > x = buf; > x.length = 4; > return x; Will fail because you're pointing into the stack of a returned function. > //4 > x = "A te" > return x; Will work - pointing into static data. > //5 > x = buf; > return x[1..4]; Will fail because you're pointing into the stack of a returned function. > //6 > return "A te"; Will work, pointing into static data. > //7 > x.length = 4; > buf[4] = 0; > strcpy (x, buf); > return x; > } Will work, x points into heap. |
Copyright © 1999-2021 by the D Language Foundation