|
I've just taken a quick look at your article but I agree with the guy. To me it seems that you are a C programmer who is quite new in C++. Defines should be avoided whenever possible. In a lot of cases defines can be replaced with template/inline functions. In some other cases long macros can be replaced to a combination of a short macro + template/inline functions/classes. Macros don't respect name spaces and they arent type safe. Still, some small stupid problems can be solved practically only with macros (for example automatically logging out filename/linenumber/functionname can be done only with a logger macro). But even when you are using a macro its better to keep the body of the macro short by immediately calling a function or intantiating/using a class. Using typedef on structs in C++ is awkward and using header guards is also deprecated in my opinion, in a large project you got a very strange error message with a duplicate (for example copy-pasted) header guard and today all major compilers support "#pragma once".
|
|
|
|
|
This is really not the place for this type of message. Your article showed up in the latest Newsletter, so those who are interested will go and look at it.
Veni, vidi, abiit domum
|
|
|
|
|
I had not come across the word psychopomp before, until you started posting in the forums recently. And last night I saw it a second time while reading a short story; strange coincidence.
Veni, vidi, abiit domum
|
|
|
|
|
Yes and no. Considering how often he changes his name, something like that had to happen sooner or later.
Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
|
|
|
|
|
I came across it not long ago[^], it was the solution for the CCC.
You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."
|
|
|
|
|
He's definitely right in that the style of code you provided is not in any way a good example of nodern, object-oriented code. Defining a struct that contains nothing but two constants is not a sensible design. Definitely not from an object-oriented view, and not even in for modular, old style C programming. For the former you'd define a boundary object singleton with methods that you could call rather than exposing the actual constants, for the latter there's no good reason not to simply use a number of individual constants - but you could also just define a function to validate the boundary range and thus hide the use of the constants inside the function implementation!
I've listed these suggestions and a few more in the other thread. (didn't even use templates - not that there wouldn't be good solutions with templates too, but there really is no need to overcomplicate things!)
Also, if you want to make a point, choose an example that is bad for non-obvious reasons. Your use of #define as a bad example totally fails to bring across the need for a const struct initialization. And to be honest, I still don't see the need in the first place, since - as outlined above - grouping the const values inside a struct was a mistake to start with.
On a sidenote, you are contradicting yourself in this article: Your reason for not using #define is that you have to recompile every time the value changes - but the same is true for every variant you bring up in the article! The only way to avoid having to recompile the code is store the values outside the code and read them at some point (which however would prevent the use of const variables...)
|
|
|
|
|
I personally feel that KISS approach is the best way.
The C language #define is THE basic way to implement MN - magic numbers.
Such MN need to be readily identifiable and should stand out.
I have an issue with things like "C++11" or whatever newfangled compiler MS comes up with where MN are covered by layers of convoluted code.
So what if MN can be implemented umpteen different ways.
Mine #define(s)are up front in StdAfx.h file. And if I need them , I do search for "define" and get the all in one swoop. Try that with global variables.
I really feel that your article is getting attention from "if it is new it must be cool" coders.
Don't worry, be happy...
Cheers Vaclav
|
|
|
|
|
'blast_vib_proc.exe': Loaded 'D:\DATA\fragmentation_model\Debug\blast_vib_proc.exe', Symbols loaded.
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\msimg32.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\comdlg32.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\shlwapi.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7601.17514_none_ec83dffa859149af\comctl32.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\shell32.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\winspool.drv', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\oledlg.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\oleacc.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.7601.17825_none_72d273598668a06b\GdiPlus.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\winmm.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\nvinit.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\AMInit32.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\uxtheme.dll', Cannot find or open the PDB file
'blast_vib_proc.exe': Loaded 'C:\Windows\SysWOW64\dwmapi.dll', Cannot find or open the PDB file
First-chance exception at 0x00743387 in blast_vib_proc.exe: 0xC00000FD: Stack overflow.
Unhandled exception at 0x77cf15de in blast_vib_proc.exe: 0xC00000FD: Stack overflow.
|
|
|
|
|
Why have you posted this, all it does is confirm that your program causes a stack overflow error? You need to show the code where the error occurs, we cannot be expected to guess what your program is doing.
Veni, vidi, abiit domum
|
|
|
|
|
Go trough your program using your debugger - The debugging stops as soon as the stackoverflow happens.
In case your program stops before entering the debug mode you might want to look into this one:
http://stackoverflow.com/questions/6267837/stack-overflow-error-in-c-before-any-step[^]
If neither one helps you I kindly ask you to post the source code of your main and the classes which are initialized at first - We can't read your mind, nor your HDD.
You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."
|
|
|
|
|
As soon as start program, not operate on any array yet, got error message:
Unhandled exception at 0x77c315de in blast_frag.exe: 0xC00000FD: Stack overflow.
Please help why ?
Thanks
|
|
|
|
|
mrby123 wrote: Please help why ? Because you have a bug in your code.
Veni, vidi, abiit domum
|
|
|
|
|
True.
Veni, vidi, vici.
|
|
|
|
|
Typical sources for stack overflows are declaring large objects on the stack and recursive function calls:
void some_func()
{
int large_array[500000];
CSomeLargeObject Obj;
some_func();
some_other_func();
}
Large objects on the stack should be avoided. Use dynamic memory allocation instead (new or malloc() ).
So check your code for the above conditions. To detect recursive calls, use the debugger and check the functions that are called for recursions.
|
|
|
|
|
So stop using so much stack.
Functions calling themselves endlessly is the usual cause. Dont do it.
|
|
|
|
|
Hi,I recently completed the book Sams Teach yourself C++ and this website was mentioned there for help in further programming process I want some suggestions about getting started with programming in GUI,i am fed up of using console for 3 years learning c and c++
|
|
|
|
|
|
Ok,Thanks
|
|
|
|
|
Farhan_Karim wrote: i am fed up of using console for 3 years learning c and c++
Depending on what "using" means in the context of "3 years" you might want to start learning a different language. Certainly if you have been doing it professionally for 3 years then it is worth consideration. Even an enthusiastic amateur might undertake it.
|
|
|
|
|
The Qt Project[^] offers a great IDE and GUI framework for C++, including examples for the usage of most of the classes.
You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."
|
|
|
|
|
Alright, I've been bugging with this one for quite a while now.
I have a struct which is const and part of a class and therefore I need to initialize it.
What I have done so far:
#ifndef BOUNDARIES_H
#define BOUNDARIES_H
typedef struct{
char upper;
char lower;
} charBoundary;
#endif //BOUNDARIES_H
#ifndef FOO
#define FOO
using namespace std;
#include <iostream> //!< Used for console output
class foo{
private:
const charBoundary versionBoundary = {
1,
-5
};
public:
};
Now I recognized that the initialization
const charBoundary versionBoundary = {
1,
-5
};
is only valid in C++11 - All compilers not supporting C++11 will choke on these lines.
Now I come to the question I want to ask:
Is there any other way to get it compilable to older compilers than making versionBoundary static or non-const or adding a constructor to the charBoundary struct?
I do not like neither of the above mentioned possibilities but if there is no other solution - What would you recommend?
Thanks in Advance
PP
You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."
|
|
|
|
|
Does it have to be const ?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Yep, thats why I ask - Without the const it would be easy, also if I'd make it static const.
But for the purpose I need it const only would be the best solution.
You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."
|
|
|
|
|
OK, this is not the most elegant solution, but here we go:
charBoundary getInitialBoundary()
{
charBoundary c ={2,-5};
return c;
}
class foo{
public:
foo() : versionBoundary(getInitialBoundary()) {}
private:
const charBoundary versionBoundary;
};
|
|
|
|
|
Dont you have to do the initialisation in the class constructor?
I am not a C++ expert, I have used it enough, but it seems as if it should go there. If not and you only need one instance of the struct shared among all instances of the clas you can make it static. (Again, not an expert here, but I seem to recall from the dregs f my memoery that this is the case, please correct me anyone if it is not so).
|
|
|
|
|