Hi, is the following code safe (it works in DEBUG) :
void takesPointer(const Type* v);//this function does read from v, it doesn't alter v in any way
Type getValue();
...
takesPointer(&getValue());//gives warning while compiling "not an lvalue"
...
Type tmp = getValue();
takesPointer(&tmp);//this is safe, and maybe I should just do it, ...
hi i'm doing a program that needs high performance of handling vector elements
vector<Class_A> object ;
1- which one is fastest to access the elements
2- which is more code simpler and not complex to deal with
index ? iterator ? pointer ?
...
Hi,
I have the following for my HashTable structure:
typedef char *HashKey;
typedef int HashValue;
typedef struct sHashElement {
HashKey key;
HashValue value;
} HashElement;
typedef struct sHashTable {
HashElement *items;
float loadFactor;
} HashTable;
I never really thought about it until now but I just realized th...
From this code:
int x = 5;
int other = 10;
vector<int*> v_ptr;
v_ptr.push_back(&x);
v_ptr.push_back(&other);
v_ptr.push_back(&x);
Is there anyway I can know who points at x, from the x variable itself, so that I don't have to search inside v_ptr for address of x? Is this possible in C++ or C++0x?
I read that when doing garbage col...
Hi
What is the difference between a constant pointer and a reference?
Constant pointer as the name implies can not be bound again. Same is the case with the reference.
I wonder in what sort of scenarios would one be preferred over the other. How different is their C++ standard and their implementations?
cheers
...
I need 2 different programs to work on a single set of data.
I have can set up a network (UDP) connection between them but I want to avoid the transfer of the whole data by any means.
It sounds a little absurd but is it possible to share some kind of pointer between these two programs so that when one updates it the other can simple get...
Hello everyone,this is very basic...but please help me if anybody know about this...
Can an array be called as a const pointer?
...
I've been trying to use SWIG to wrap around a simple library that uses ioctl() to populate a structure like the following:
struct data
{
header* hdr;
void* data;
size_t len;
};
data is a pointer to a buffer, len is the length of that buffer.
I'm unable to figure out how to convert data to a Python string (or array). Furthermore...
I just need some clarification on variables
A normal variable has 2 "parts" to it?
one part is the actual value and the other part is the location of that value in the memory
Is that right?
So a pointer variable is just the location part of a normal variable, and it doesn't have value itself?
...
I am moving to C++ from Java and I am having a lot of trouble understanding the basics of how C++ classes work and best practices for designing them. Specifically I am wondering if I should be using a pointer to my class member in the following case.
I have a custom class Foo which which represents the state of a game on a specific turn...
What happens inside memory if we try to free a pointer which is pointing to NULL?
Is that ever valid?
Why does it not show any warning/error messages?
...
My project has both managed & unmanaged code. I wrote a class cIVR in managed code, while defining it in an unmanaged cpp file. The project has been working fine for some time.
Now I need to call a member function of one of objects in array 'arrChannels' from another function in the same file.
During array definition it's not allowing...
I have this code, but it won't compile and i can't understand what is wrong - i guess the pointering of the vector is not correct.
My idea was to collect some numbers in main() and store them in a vector and array, and then pass the memory address of them to a function, and using a pointers to print the data stored.
I came up with this...
// clickable blocks
$(".product").click(
function () {
window.location = $(this).find('a').attr("href").css("cursor", "pointer");
return false;
});
The container is made clickable but the cursor remains the same. Why isn't the css selector working?
...
Hi,
ok it is 'easy' to make jna wrapper solution for mapping exported functions within dll using jna:
long f1(int x), just int
long f2(char* y), just char[]
but how to deal with long f3(char** z) ?
I need f3's result(long) as well as z value on java side.
Please don't say cpp code should be rewritten to avoid this:-)
...
main(){
char *cmd1[20] = {NULL};
int x = parse_command(cmd1);
printf("%s\ ",cmd1[0]);
}
parse_command(char *inTempString){
char tempString[256];
(call to function that assigns a string to tempString)
cmd1[0] = tempString;
}
There is a problem when printing out the cmd1[0] within main. I am pretty sure that it is a da...
How does a pointer points to [-1]th index of the array produce legal output everytime. What is actually happening in the pointer assignment?
#include<stdio.h>
int main()
{
int realarray[10];
int *array = &realarray[-1];
printf("%p\n", (void *)array);
return 0;
}
Code output:
manav@workstation:~/knr$ g...
I have the following code:
void * storage = malloc( 4 );
__asm
{
//assume the interger 1 is stored in eax
mov eax, storage //I've tried *storage as well but apparently it's illegal syntax
}
/* other code here */
free(storage);
However, in the code, when I dereference the storage pointer ( as in *(int *)storage ), I do not ge...
I am working on a queue data structure. The structure is:
struct queue
{
char array[MAX_LENGTH][8];
int back;
};
It is designed to store a list of MAX_LENGTH strings that are 7 chars long.
I wish to push a 1D array of 8 chars (well, 7 chars and \0, just like the array in the struct).
I have this push code:
void push (struct queue ...
I create something like a list of functors (functions pointers). Then I write them in binary form into file. The problem is, that, functor - is a simple function pointer. (correct me if I'm wrong.) But the address of function is different from one run to another.
So, the question - is there any way to create list of functors that will b...