What is the difference between this:
somefunction() {
...
char *output;
output = (char *) malloc((len * 2) + 1);
...
}
and this:
somefunction() {
...
char output[(len * 2) + 1];
...
}
When is one more appropriate than the other?
thanks all for your answers. here is a summary:
...
Although this "conversation" could quickly degenerate into something like "this is how I think ..." the question is not. Has any "big name entity" (e.g., google or the likes, Scott Meyers or the likes, etc.) published anything freely available which dictates/suggests what they feel the syntax guides lines for their code base should be f...
I'm writing a Qt application that uses Botan. For the Windows version I decided to use the precompiled DLL, so I downloaded the installer, installed Botan in C:\botan and added:
win32:INCLUDEPATH += C:/botan/include
win32:LIBS += -L"C:\botan" -lbotan
to my .pro file. However I'm getting linker errors (undefined reference to...) during...
int x = 5;
cout<<(char)x;
the code above outputs an int x in raw binary, but only 1 byte. what I need it to do is output the x as 4-bytes in binary, because in my code, x can be anywhere between 0 and 2^32-1, since
cout<<(int)x;
doesn't do the trick, how would I do it?
...
I have successfully installed boost, compiled binaries, and built bcp. I have also been able to extract the regex library using bcp. After doing this, I found a gcc_gen.sh script and bunch of makefiles under
my_exported_boost_regex/libs/regex/build/
and used one of them to make
my_exported_boost_regex/libs/regex/build/gcc/libboos...
During program optimization, trying to optimize a loop that iterates through a vector, I found the following fact: ::std::vector::at() is EXTREMELY slower than operator[] !
The operator[] is 5 to 10 times faster than at(), both in release & debug builds (VS2008 x86).
Reading a bit on the web got me to realize that at() has boundary che...
Can you guys see any obvious error in this query? The error im getting is: `Unknown column 003ADF50 in field list. 003ADF50 wtf?
query << "UPDATE `record` SET `record` = " << lastRecord << ", `time` = " << time;
...
I'm using OpenGL and drawing polygons in a 2D view. How could I blur a polygon, without using glsl, and only things like stencil buffer and stuff. Thanks
...
I know how to move, rotate, and scale, but how does skewing work? what would I have to do to a set of verticies to skew them?
Thanks
...
In Photoshop there is a tool that allows the selection to be "Distorted". This allows easy shadow creation among other things. How could this sort of distortion be applied for a polygon (a bunch of points)?
Thanks
...
Hi ! I am a newbie to C++ and facing a problem.
I read in a book that memory is allotted to a static variable, once the object is created of that class. Now, what if I make this static variable global ? When would be it initialized in that case ?
Plus, I have also read in some articles that static variables are allotted on heap and the...
Greetings,
I've implemented a low-level keyboard hook as described here. This works fine under WinXP.
Problem is, under Windows 7 the left and right windows keys are no longer intercepted.
Any suggestions as to how to recapture these keys under Windows 7 greatly appreciated!
Cheers,
Rony
...
Using EnumWindows and GetWindowText, I see many titles with "M' and "Default IME".
What is their primary function?.. It seems to be something quite fundamental.
...
Here's the current code:
const complex complex::operator+(const complex &right)
{
complex result;
result.realPart = realPart + right.realPart;
result.imPart = imPart + right.imPart;
return result;
}
How do i modify so that
a = b + c + d;
is allowed?
...
Hi all,
i need to find the default icon of a windows executable (PE file = dll, exe, com..) programatically. I do know how to walk throught the resources and identify what is an icon, what a cursor etc, but as far as i know none of the icons is in any way marked as the default one. So, does somebody know, how to find the default icon? M...
Hi All,
I'm trying to write console data into a separate text file in cpp. Anybody help me with sample code.
...
take two following classes and their constructors as samples:
class One{
public:
One(int a,int b):adad1(a),adad2(b){}
private:
int adad1;
int adad2;
};
class Two{
public:
Two(int input[]){
for (int i=0;i<10;i++)
araye[i]=input[i];
}
private:
int araye[10];
};
considering objects with static storage duration, I t...
Whats the best way to send float, double, int16 over serial on Arduino?
The Serial.print() only sends values only ascii encoded. But I want to send the values as bytes. Serial.write() accepts byte and bytearrays, but whats the best way to convert the values to bytes? I tried to cast an int16 to an byte*, without luck. I also used memcpy,...
In C++ primer 4th edition by Lippman, compound assignment operators for iterator for vector and deque are given :
iter1 += iter2
iter1 -= iter2
Compound-assignment versions of iterator addition and subtraction. Assigns the value of adding or subtracting iter1 and iter2 into iter1.
But when I want to use them, it gives error. More...
I'm new to Boost, but not to functional programming, and I'm trying to see where Boost can help me out.
I have a list of 2D points, and I want to extract the minimum x coordinate. The Point class has a member function float x() const so I can use boost::mem_fn as follows:
boost::mem_fn(&Point::x)
But in order to use std::min_element,...