|
yadrif wrote: mainBuf = (char*)malloc(sizeof(char));
*mainBuf = 'AB';
What exactly are you expecting to do with this? You are passing 1 to malloc() , yet you are trying to stuff, albeit incorrectly, 2 bytes into mainBuf . Why?
Why are you using malloc() with a C++ program. Use new instead:
char *mainBuf = new char[3];
strcpy(mainBuf, "AB");
delete [] mainBuf;
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: yet you are trying to stuff, albeit incorrectly, 2 bytes into mainBuf
Nope, 'AB' is one byte (it is different than "AB"), this will be truncated to one byte. But I think the compiler should give an error there instead of a warning...
|
|
|
|
|
Point taken, but it's wrong nonetheless.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Nope, 'AB' is a short int that will truncated to one byte
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I was just playing around with the code, no real application here. Just learning.
I actually started by writing a sample to use a pointer to a pointer. Just to learn how it worked and actually use what I read. I then for some reason decided to stuff 'AB' into what the pointer points to just to see what would happen. I then removed the pointer to pointer part to simplify it before posting the question.
Maybe this just gets into the realm of undefined behavior. I thought perhaps there would be an explanation as to why it does what it does.
Thanks.
|
|
|
|
|
I'm sorry no one here has taken the effort to give you a good reply. I also would like to know the answer.
I've never used syntax like 'AB' since I've always dealt with ASCII strings, and the single 'apostophe' returns the character (integer) value of a single character between the marks. I don't know what it does in your context, but appears that perhaps it's playing "little endian" and returning the least-significant byte of a 16-bit value???
Did you try declaring the pointer as a wchar_t* instead? This might work.
Maybe some real coders will see your question in a while and respond with a real answer.
David
|
|
|
|
|
DQNOK wrote: but appears that perhaps it's playing "little endian" and returning the least-significant byte of a 16-bit value???
This is correct.
|
|
|
|
|
I wrote a C++ code for analyzing texts few years ago and it works perfectly. I am now trying to make it a windows-based application by integrating it into Visual C++ using visual studio. This has been an ache!
I first got
fatal error C1010: Unexpected end of file while looking for precompiled header directive.
It was not too difficult to correct this as there are many similar experiences recorded in various discussion groups on the Internet.
However, when I added #include "stdafx.h" as directed in various responses to the c1010 error on the Internet, I got the following errors
error C2095: syntax error: 'function-style cast'
error C2226: syntax error: unexpected type 'T'
error C2095: syntax error: ')'
and a number of other similar errors.
All these were generated by a code line 1 below:
1 template <class t=""> T max(T x, T,y)
2 {
3 return (x > y) ? x : y;
4 }
any ideas on what could be wrong?
taintransit
|
|
|
|
|
Please, when posting code (and even more when posting template code), replace all the < and > symbols with the formatting tags just aboce the emoticons (otherwise, they won't be visisble).
To your question: didn't you forget a class keyword ? template <class T> T max(T min, T max)
|
|
|
|
|
Cedric Moonen wrote: ...replace all the < and > symbols with the formatting tags...
Hi Cedric. You actually only need to replace the < symbol.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Oh well, then that makes things even more easier
Thanks for the tip.
|
|
|
|
|
Unless > and < were eaten in your post, it looks like the syntax for the template is incorrect. It should be something closer to:
template< typename T >
T max( T x, T y ) Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Yes you are right. The angle brackets were eaten up in the post. Cedric Momen pointed this out in his response.
jhwurmbach suggested that I avoid pre compiling the headers. It worked! Thanks every body.
taintransit
|
|
|
|
|
taintransit wrote: 1 template T max(T x, T,y)
Look at this line closely.
taintransit wrote: any ideas on what could be wrong?
For a hint, try renaming the macro.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Stop! No!
Don't try to precompile your C-Headers.
Instead, switch off precompiled headers, either for the whole project (in the project properties) or for single files (in the properties of the file)
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
Thanks a million jhwurmbach. You have just halted my one week of sleepless nights.
Thanks also to David Crow, Cedric Moonen and James Twine for all your suggestions.
taintransit
|
|
|
|
|
How can I add an extra button control on the title without affecting existing system menu or without disturbing existing Close button and Icon.
When I tried to handle Non clent paint message, previous button changes its color and state which I don't want.
Is there any way to do this?
msc
|
|
|
|
|
|
Hi Experts,
Could anyone tell me how to detect the Microsoft office outlook installed on my machine (any version)?
Thanks in advance.
|
|
|
|
|
post this in os/sysadmin forum and delete from here.
i will answer it there.
|
|
|
|
|
See here.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi All,
I am debugging the program by adding the break point at some function.Suppose I want to find out which function is called when I perform particular actions. Is there any method to identify which function is called at particular event.Because I can not predict which function gets called so I can not add break point at that function.Can we add break point at all function in project by any short cut method of IDE. Please send me solution if anybody have.
Thanks in Advance
Atul
Atul
|
|
|
|
|
Set a breakpoint at the position where the function is called and then use the debugger command "step into".
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|