|
Ravi Bhavnani wrote:
I used the Dragon Book[^] eons ago
Aaah! the Dragon Book does bring back memories !!!
This[^] might also be useful...
"It was when I found out I could make mistakes that I knew I was on to something."
-Ornette Coleman
|
|
|
|
|
Are you taking a class on compiler construction at a college?
Check out these books on compiler construction.
The Dragon Book by Aho
Crafting a Compiler by Fisher and LaBlance
Kuphryn
|
|
|
|
|
Nope not yet, it's only my first year, we are learning Oberon now but.. blech :P
Kuniva
--------------------------------------------
|
|
|
|
|
|
|
I quite like Modern Compiler Design[^].
Most courses and texts cover simple parsing algorithms such as LL(1), LL(k) and LALR(1). These algorithms are powerful, but you really have to structure your grammar carefully to make them work - you tend to have to compromise your language, designing it around the parsing algorithm.
Famously, Bjarne Stroustrup did not do this, with the end result that C++ cannot be parsed by an LALR(1) algorithm (you must typically feed back into the lexer).
Generalised LR parsing algorithms are beginning to perform nearly as well as LALR parsers generated by yacc or bison . If you just want to parse your language and be done with it, consider the Elkhound[^] parser generator.
|
|
|
|
|
I'm using the system() command to call a batch file - This is done from a dialog box based program and the system() command is used within a loop - Each iteration causes the command.com window to get focus and control (the window pops up in front of whatever program I'm working with) - How can I minimize the window each time it is called, and if necessary, leave the focus with whatevery window has it ?
|
|
|
|
|
Try START /MIN application
|
|
|
|
|
I'll try this asap - Thanks
|
|
|
|
|
Use CreateProcess() instead of system(). This gives you far more control.
Here is some code I use in ED.
BOOL
Execute_OS_Program( char* pszCommandLine, char* pszWorkingDir, const int Run_Opts, int* const pnErrorCode )
{
PROCESS_INFORMATION piProcInfo;
STARTUPINFO siStartInfo;
DWORD dwCreationFlags = 0x00;
bool stat;
ZeroMemory( &siStartInfo, sizeof( STARTUPINFO ) );
siStartInfo.cb = sizeof( STARTUPINFO );
siStartInfo.dwFlags = STARTF_USESHOWWINDOW;
siStartInfo.wShowWindow = SW_SHOWNORMAL;
dwCreationFlags = CREATE_NEW_CONSOLE;
ZeroMemory( &piProcInfo, sizeof( PROCESS_INFORMATION ) );
stat = CreateProcess( NULL,
(char*)pszCommandLine,
NULL,
NULL,
FALSE,
dwCreationFlags,
NULL,
pszWorkingDir,
&siStartInfo,
&piProcInfo
) != FALSE;
if ( stat )
{
CloseHandle( piProcInfo.hThread );
*pnErrorCode = 0;
if ( Run_Opts & SE_WAIT )
WaitForSingleObject( piProcInfo.hProcess, INFINITE );
}
else
*pnErrorCode = GetLastError();
return stat;
}
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
Thanks - I'll take a look at this method today
|
|
|
|
|
Hello.
I have library foo.lib, which has class foo with a static member variable (see below), constuctor of class foo refers to the static member during initialization. I am using this library in my program, which has global variable of type foo.
The problem is that global_foo is initialized before foo::s_a is, so global_foo.m_var is not equall to 1 as I want it to be. How can I avoid this situation? Is there a way to force global initializations to be in a certain order?
Thank you.
P.S. I found on the net that solution could be mentioned in
Schwarz, "Initializing Static Variables in C++ Libraries", C++ Report. Vol1 No2, Feb. 89, pp1-4.
But I can not find this article online, and I do not have access to the C++ Gems book, which should have it.
--- foo.h
class foo
{
static int s_a;
int m_var;
foo(){m_var=s_a;}
}
--- foo.cpp
#include "foo.h"
int foo::s_a=1;
--- my_prog.cpp
#include "foo.h"
foo global_foo;
mian{}
Regards,
Alexander.
|
|
|
|
|
Move the ctor body to foo.cpp .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I can not move ctor. The situation is that static member should be defined in the lib file, while derivatives of the main class will be decleared as global objects in the main program.
Regards,
Alexander.
|
|
|
|
|
Ummm... try the following approach:
--- foo.h
class foo
{
static int& s_a();
int m_var;
foo(){m_var=s_a();}
}
--- foo.cpp
#include "foo.h"
int& foo::s_a()
{
static int s_a_var=1;
return s_a_var;
}
--- my_prog.cpp
#include "foo.h"
foo global_foo;
mian{}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks a lot, this method works fine. Though it looks more like a trick, rather then a way to do such things Anyway it does work.
Regards,
Alexander.
|
|
|
|
|
The technique can be deemed a trick, but it is a very common one, since it helps to solve a long standing problem that some call the static initialization order fiasco[^]. Also, it is routinely used in some implementations of the Singleton pattern.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks for the link, nice to have it in favorites And it does work!
Regards,
Alexander.
|
|
|
|
|
ACoording to C++ specification:
All static variables are initialized to 0(NULL) by loader before being initialized by CRT.
So, if you can changed your LIB if available and provide check in you constructor like that:
...<br />
class foo<br />
{<br />
static bool s_initialize;<br />
static int s_a;<br />
int m_var;<br />
foo()<br />
{<br />
if (!s_initialized)<br />
{<br />
s_a = 1;<br />
s_initialized = true;<br />
}<br />
m_var=s_a;<br />
}<br />
...<br />
int foo::s_initialized = false;<br />
int foo::s_a=1;<br />
...
Or just use (s_a == 0) check if 0 is not possible value...
"...Ability to type is not enough to become a Programmer. Unless you type in VB. But then again you have to type really fast..."
Me
|
|
|
|
|
It looks like s_initialized will be reset to false again once "int foo::s_initialized = false;" is executed, which means that initialization will be done twice.
Regards,
Alexander.
|
|
|
|
|
How about this then?:
class foo<br />
{<br />
static bool s_initialized;<br />
static int s_a;<br />
int m_var;<br />
foo()<br />
{<br />
if (!s_initialized)<br />
{<br />
s_a = 1;<br />
s_initialized = true;<br />
} <br />
m_var=s_a;<br />
}<br />
};<br />
bool foo::s_initialized;<br />
int foo::s_a=0;
Weird and funny!...
"...Ability to type is not enough to become a Programmer. Unless you type in VB. But then again you have to type really fast..."
Me
|
|
|
|
|
I guess it will be the same. foo::s_initialized will be initialized again to something we are not sure what But I am guessing it might work as well. I am using approach suggeseted by Joaqun. But thank you for your help. It is good to know alternative ways
Regards,
Alexander.
|
|
|
|
|
how create thread into the same class?
*.h
class TheClass : CDialog
{
public:
TheClass(CWnd* pParent = NULL):
void StartThread();
UINT TheThread(LPVOID);
}
*.cpp
UINT Theclass::TheThread(LPVOID)
{
//Code for th thread
}
void TheClass::StartThread()
{
DWORD dwThreadId, dwThrdParam = 1;
HANDLE hThread;
hThread = CreateThread(NULL,0, TheThread, &dwThrdParam,0,&dwThreadId); // error c2664
}
How cast the TheThread param correctly?
Thanks you
|
|
|
|
|
This is one of the most asked issues here in CP. Take a look at the Code Project Visual C++ Forum FAQ[^], item 6.1 "Why can't I use a member function as a callback?"
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi,
I'm searching for a possibility to fade out a programs main window to grey while another dialog message is hanging around - as been seen when you choose Start->Shutdown in Windows XP.
Therefore I looked into the GDI+ documentation but found something for the alpha-channel (could be used to make windows transparent I guess).
What is the best way to fade a window to grey ? Did I have to make a in memory bitmap of the window and change that bitmap's color palette ?
Can somebody can give me a hint which direction I should consider ?
best regards
a
|
|
|
|