Most people suggest that learning assembly is essential, its important to know the underlying workings of the computer, and so forth. But what I'm looking for are some practical suggestions that will make the effort of learning Assembly to be worth it.
What are your suggestions? What am I missing out on by not learning Assembly and poin...
I have a function inside a class that returns a reference to a member variable.
std::vector<uint8> & getBuffer() const
{
return m_myBuffer;
}
Now say in another class I call this method:
int someFunction()
{
std::vector<uint8> myFileBuffer = myFile.getBuffer();
}
This line calls the copy constructor of vector and makes me a l...
Sorry for such a newbie question but there is something I do not quite understand the difference between a C# reference and a pointer. They both point to a place in memory don't they? The only difference I can figure out is that pointers are not as clever, cannot point to anything on the heap, are exempt from garbage collection, and can ...
Disclaimer: This is for a homework assignment, but the question is not regarding the assignment, just about general syntax weirdness.
I'm trying to use libpcap in the context of a much larger program, but when I try to get the packet header and data for each packet gcc complains that the third parameter to pcap_next_ex is of an incompat...
Hello, how expensive is it to perform the dereference operation on a pointer in C++? I can imagine that the memory transfer is somehow proportional to the object size, but I want to know how expensive the dereference operation part is.
Thank you.
...
I'm trying to convert a struct to a char array to send over the network. However, I get some weird output from the char array when I do.
#include <stdio.h>
struct x
{
int x;
} __attribute__((packed));
int main()
{
struct x a;
a.x=127;
char *b = (char *)&a;
int i;
for (i=0; i<4; i++)
printf("%02x ", b[i]);
...
my problem is reading the pixel data correctly once i have the pointer
so i have an image that takes up the whole iphone screen that has no alpha channel (24 bits per pixel, 8 bits per component, 960 bytes per row) and i want to find out the color of a pixel at a particular XY coordinate.
i have the pointer to the data
UInt8 *data = C...
First of all I have to admit that my programming skills are pretty limited and I took over a (really small) existing C++ OOP project where I try to push my own stuff in. Unfortunately I'm experiencing a problem which goes beyond my knowledge and I hope to find some help here. I'm working with a third party library (which cannot be change...
Why does the following code in C work?
const char* str = NULL;
str = "test";
str = "test2";
Since str is a pointer to a constant character, why are we allowed to assign it different string literals? Further, how can we protect str from being modified? It seems like this could be a problem if, for example, we later assigned str to a ...
In C++, arrays cannot be passed simply as parameters. Meaning if I create a function like so:
void doSomething(char charArray[])
{
// if I want the array size
int size = sizeof(charArray);
// NO GOOD, will always get 4 (as in 4 bytes in the pointer)
}
I have no way of knowing how big the array is, since I have only a point...
i was learning about c++ pointers... so the "->" operator seemed strange to me... instead of
ptr->hello();
one could write
(*ptr).hello();
because it also seems to work, so i thought the former is just a more convenient way
is that the case or is there any difference?
...
When implementing a singleton in C++, is it better for GetInstance() to return a pointer to the singleton object, or a reference? Does it really matter?
...
I recently wrote a program to help me understand the basics of memory pointers in C++, I chose a simple prime number finder.
I finally got it to work. (yay for debugging!)
And I let it run to see how far it goes, it gets to prime #815389 with my verbose tells me is the 65076th prime, I get an app crash. The one thing I could think of w...
I want to know the runtime type of a base class pointer, I know you can use dynamic_cast.
is there any better way?
...
Is it safe to assume that NULL always translates to false in C?
void *somePtr = NULL;
if (!somePtr) {
/* This will always be executed? */
}
Or should an explicit check against the value of NULL be made?
...
I would like to copy lines from stdin to an array of character pointers. For example if the user entered the following "the\nquick\nbrown\nfox" then I would like to have an array that looks like
arr[0] = "the" arr[1] = "quick" arr[2]
= "brown" arr[3] = "fox"
Any pointers?
...
void foo(void **Pointer);
int main ()
{
int *IntPtr;
foo(&((void*)IntPtr));
}
Why do I get an error?
error: lvalue required as unary ‘&’ operand
Thanks
...
I get this message when compiling C++ on gcc 4.3
error: ‘NULL’ was not declared in this scope
It appears and disappears and I don't know why. Why?
Thanks.
...
I could be totally wrong here, but as I understand it, C++ doesn't really have a native "pointer to member function" type. I know you can do tricks with Boost and mem_fun etc. But why did the designers of C++ decide not to have a 64-bit pointer containing a pointer to the function and a pointer to the object, for example?
What I mean s...
I have a function that takes pointer to pointer to struct.
struct ABC;
void func(ABC ** ptr); //func is provided by someone else and i don't know about the implementation.
{
}
Now, i have following code.
ABC xyz[2];
ABC * ptr = xyz;
ABC **dptr1 = &ptr; //pointer to ponter
ABC ** dptr2 = (ABC **)malloc(2*sizeof(struct abc*))...