|
I think it is bad because you can miss important warnings (things that you didn't thought about). You should get rid of the warnings instead of silenting them. I only disable them on some rare occasions.
C4181: why do you put the const keyword then ? If it will be ignored ? It let you think that it is used but it isn't so it can lead to confusion. Why don't you just remove it ? This will lead to the same result without warning.
C4018: why do you mix signed and unsigned ? That probably results to a bad design. They don't have the same range so if you start with a signed number, stick to it. On some rare occasion you will need to mix them, but then use an explicit cast.
C4244:
Nelek wrote: SOLUTION: casting to the correct typ, but dont needed, but in this case I wanna lose the decimals by truncating and the constants must be float/double for other places to be used. And I have about 90 times this warning
Cast the complete block: (int)(4*GWIDTH)
Nelek wrote: warning C4308: Negative Ganzzahlkonstante in vorzeichenlosen Typ konvertiert
//Conversion of negative integer constant in unsigned type
REASON: file->Seek (-3 * sizeof (BYTE), CFile::current);
That's typically one of the warning you shouldn't neglect, because your code is wrong. The warning tells you that it converts the -3 to an unsigned, so the result won't be what you expect. It does that because sizeof returns an unsigned type and so, when doing the multiplication your compiler will convert the -3 to unsigned type so that it can multiply both operands.
|
|
|
|
|
Thanks for your answer.
C4181: I didn't know that it would be ignored. I put that in const to avoid changes in the function by error, but if it is ignored... then it is useless. Erased and warnings away.
C4018: casted in the places, warnings away
C4244: casted in the places, change the return in a function and the warnings away
C4308: changed to file->Seek (((UINT) -3) * sizeof (BYTE), CFile::current);
is that correct? I want to go back in 3 bytes to reread the last block because it contains particular info that i need to start the next block
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
Nelek wrote: C4308: changed to file->Seek (((UINT) -3) * sizeof (BYTE), CFile::current);
is that correct? I want to go back in 3 bytes to reread the last block because it contains particular info that i need to start the next block
Hi, in this case, the ((UINT)-3) will be converted to 3, advansing the position in the file instead of going back, the cast should be in the sizeof :
file->Seek (-3 * (long)sizeof(BYTE), CFile::current);
|
|
|
|
|
you are totally right. Thanks for avoiding me an assertion
EDIT: I executed the program with my first option and worked ok, but i have anyways changed it
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
Nelek wrote: But there are some times that the warnings are not relevant or don't matter, due to the code.
Compiler warnings are always relevant, else they would not exist.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
You are right... I wrote it in a false way.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
It makes sense from time to time. Just don't abuse it.
It just that, a warning (not an error). The programmer goes and scrutinizes the code and makes a decision. If they deem the existing code sound, then disabling the warning for that specific chunk of code makes perfect sense.
Make sure to turn the warning back on after the section of code in question that has been deemed by the programmer as fine. That way every future warning will need to be scrutinized by the programmer and they get to decide if it's a false alram or not.
#pragma warning (disable: XXXX)
// Some code that is deemed OK after reviewing warnings
#pragma warning (default: XXXX)
|
|
|
|
|
I didn't know the how to enable them another time, thanks or the tip
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
You can also use /wdn in project settings.
Project | Properties | C/C++ | Command Line
Disables the specified compiler warning where n is the compiler warning number.
For example, /wd4326 disables compiler warning C4326.
Please refer here[^] for more information.
|
|
|
|
|
|
You are correct Cedric.
As per MSDN[^] "Treats all compiler warnings as errors. For a new project, it may be best to use /WX in all compilations; resolving all warnings will ensure the fewest possible hard-to-find code defects."
Regards,
Paresh.
|
|
|
|
|
How to remove the /COMMENT directory from the project settings
|
|
|
|
|
hi
i am on my pc on LAN and i woud like to make an application to reteive Data from a database located on the server of the LAN.
i am programming with MFC,and i use the class CRecordset,and the method conssit to access to the database from ODBC (with ingres DATABASE), but when i add the the new class (MFC ODBC Consumer),i can't got the tables of the database(because when database is located on same PC,the ODBC give u the hand to show him the path of the database and the table that i would like to work with).
can you help me ?
|
|
|
|
|
The application does not need to know the location of the database it is accessing, that's what the DSN is for. Reconfigure your DSN so that it "points to" the correct location of the database. Then when you create your CRecordset object, reference the correct DSN.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
template <class beingcounted="">
class Counted
{
public:
class TooManyObjects{};
static int getObjectNum()
{
return m_ObjectNum;
};
protected:
Counted();
Counted(const Counted& count);
~Counted() { --m_ObjectNum; };
private:
static int m_ObjectNum;
static const size_t m_MaxObjectNum;
void init();
};
template <class beingcounted=""> Counted<beingcounted>::Counted()
{
init();
}
template <class beingcounted=""> Counted<beingcounted>::Counted(const Counted& count)
{
init();
}
template <class beingcounted=""> Counted<beingcounted>::init()
{
if(m_ObjectNum > m_MaxObjectNum)
{
throw TooManyObjects();
}
++m_ObjectNum;
}
class Printer: private Counted<printer>
{
public:
static Printer* makePrinter();
static Printer* makePrinter(const Printer& rhs);
~Printer();
void reset();
void performSelfTest();
using Counted<printer>::getObjectNum;
using Counted<printer>::TooManyObjects;
private:
Printer();
Printer(const Printer& rhs);
};
int Counted<printer>::m_ObjectNum = 0;
const size_t Counted<printer>::m_MaxObjectNum = 5;
Printer::Printer()
{
}
Printer::Printer(const Printer &rhs)
{
}
Printer::~Printer()
{
}
Printer* Printer::makePrinter()
{
return new Printer();
}
when I compile it, an unresolved symbol
"protected _thiscall":Counted<class printer="">:Counted<class printer="">(void)" are function
"private: _thiscall Printer:Printer(void)" reference
I don't know its meaning. How can I resolv it link error?
Many thanks.
|
|
|
|
|
Your code is almost unreadable, see point 5 here[^].
You should also replace the < and > characters by the symbols that are just above the emoticons otherwise they will be eaten (and for template, that will be quite difficult to understand).
And please, post the exact error message.
|
|
|
|
|
Why did you not preview your post prior to submitting it? Had you done so, you would have noticed a lot of important code has been hidden (it's not actually removed). Modify your post and surround the code with <pre> tags, and use the < above the smileys instead of the actual < character.
With one small change, your code compiled fine for me.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
template <class BeingCounted>
class Counted
{
public:
class TooManyObjects{};
static int getObjectNum()
{
return m_ObjectNum;
};
protected:
Counted();
Counted(const Counted& count);
~Counted() { --m_ObjectNum; };
private:
static int m_ObjectNum;
static const size_t m_MaxObjectNum;
void init();
};
template <class BeingCounted> Counted<BeingCounted>::Counted()
{
init();
}
template <class BeingCounted> Counted<BeingCounted>::Counted(const Counted& count)
{
init();
}
template <class BeingCounted> Counted<BeingCounted>::init()
{
if(m_ObjectNum > m_MaxObjectNum)
{
throw TooManyObjects();
}
++m_ObjectNum;
}
class Printer: private Counted<Printer>
{
public:
static Printer* makePrinter();
static Printer* makePrinter(const Printer& rhs);
~Printer();
void reset();
void performSelfTest();
using Counted<Printer>::getObjectNum;
using Counted<Printer>::TooManyObjects;
private:
Printer();
Printer(const Printer& rhs);
};
int Counted<Printer>::m_ObjectNum = 0;
const size_t Counted<Printer>::m_MaxObjectNum = 5;
Printer::Printer()
{
}
Printer::Printer(const Printer &rhs)
{
}
Printer::~Printer()
{
}
Printer* Printer::makePrinter()
{
return new Printer();
}
error LNK2019 unresolved symbol
|
|
|
|
|
richardye wrote: error LNK2019 unresolved symbol
Which means nothing out of context.
My guess is the following line is in error:
template <class BeingCounted> Counted<BeingCounted>::Counted(const Counted& count)
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi!
I m working on a Access project in which i want to create and execute a module
programiticaly in VC++.
I also try to use OLE function of Access bt in the Access class there is no function to create module. How i can do this.
Pls help me...regrading this.
_
ansh
|
|
|
|
|
I added WM_CTLCOLOR and coded the following lines in it.
HBRUSH DlgTest::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hBrush = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (pWnd->GetDlgCtrlID() == IDC_CHECK1)
{
pDC->SetTextColor(m_checkBoxColor);
pDC->SetBkMode(TRANSPARENT);
}
return(hBrush);
}
and in onInitdialog i added the following lines
m_checkBoxColor = RGB(255,255,255);
GetDlgItem(IDC_CHECK1)->Invalidate();
where m_checkBoxColor is COLORREF variable.
This works fine when XP themes service off. When it is on it is not working. How to make it work when themes service is on
|
|
|
|
|
well you could try handling the NM_CUSTOMDRAW for when XP themes are enabled...
|
|
|
|
|
Can we access contents of history folder?
Thanks in Advance
|
|
|
|
|
TCHAR szPath[_MAX_PATH];<br />
SHGetFolderPath(NULL, CSIDL_HISTORY, NULL, SHGFP_TYPE_CURRENT, szPath);
|
|
|
|
|
Thanks for your reply but i want to access the contents of the history folder.How can i do it?
|
|
|
|