Hi,
I think the title is clear on explaining my problem.... consider the following snippet:
class Critter {
int m_Age;
};
int main()
{
vector<Critter* const> critters;
for(int i = 0; i < 10; ++i)
critters.push_back(new Critter());
critters[2] = new Critter();
return 0;
}
Shouldn't the line critters[2] =...
Options A:
if (NULL == pSomethingColumn) // Yes, we use Yoda conditions
if (NULL != pSomethingColumn)
Or
if (pSomethingColumn)
if (!pSomethingColumn)
I am looking for references explaining the reasoning as well.
I have heard some people say that technically NULL does not have to be defined as 0, but come on! if that was the case, ...
So, I'm having a bit of pointer issues.
I'm writing a function that stores memory addresses in a[].
These memory addresses point to actual data values in b[].
I'm having trouble getting the memory address from b to store in a.
// Assume these are initialized to 0 outside of this snippet
char a[100];
char b[100];
b[0] = 42; // Some valu...
Possible Duplicates:
Can the Size of Pointers Vary Depending on whats Pointed To?
Are there are any platforms where pointers to different types have different sizes?
Is it possible that the size of a pointer to a float in c differs from a pointer to int? Having tried it out, I get the same result for all kinds of pointers.
...
I moved my code to use std::vector<char> instead of char *mem = malloc(...) but now I am facing a problem that I can only access the vector data through operator [] but not via a pointer.
I can't write stuff like:
std::vector<char> data;
fill_data(data);
char *ptr = data;
Before I could do this:
char *data = malloc(100);
fill_data2(...
Hi,
I am trying to understand array declarations, constness, and their resulting variable types.
The following is allowed (by my compiler):
char s01[] = "abc" ; // typeof(s01) = char*
const char s02[] = "abc" ; // typeof(s02) = const char* (== char const*)
char const s03[] = "abc" ; // typeof(s03) = char const* (== const char...
Hi,
I'm trying to consume an ASP.net Web service, and found a utility called WSDL2ObjC.
Now I'm trying to use it, and basic use is working (asking for simple data types, such as booleans or strings), but now I'm requesting an array of the "EmailServiceSvc_Email" structure, which contains "subject", "from" and "message" properties.
The...
Hello,
I've have investigating the effect of __restricting certain pointers in a C++-code, when compiling it via the GCC-compiler.
It turned that not only the run-time remains quite the same, but the executable doesn't seem to have changed, the size in bytes is exactly the same as before.
My GCC-version is
gcc version 4.3.2 [gcc-4_3-...
If a particular type(say int,char,float,..) pointer is incremented the value of pointer variable increased by number which is equal to size of the particular data type.If a void pointer points to data of x size for increment operation how it will point to x size ahead? How compiler knows to add x to value of the pointer?
...
Hi there,
I have C code which uses a variable data, which is a large 2d array created with malloc with variable size. Now I have to write an interface, so that the C functions can be called from within Python. I use ctypes for that.
C code:
FOO* pytrain(float **data){
FOO *foo = foo_autoTrain((float (*)[])data);
return foo;
}
...
I have been tasked with removing RogueWave components from a legacy C++ codebase. To do so, I am attempting to build wrappers around the existing components, make sure that the code functions the same, and then choose a different library like boost to stick into the wrappers.
One of the problems I am coming against is that much of the ...
Alright, I know how you normally would declare a pointer:
void SomeFunction(array<float> ^managedArray)
{
pin_ptr<float> managedArrayPtr = &managedArray[0];
}
This works fine except when managedArray contains no elements. In that case, it throws an IndexOutOfRangeException.
In C# you can do this:
void SomeFunction(float[] managedA...
Using
gcc 4.4.3 c89:
I am just working on the following code below:
I just have some questions about dereferencing the src pointer. Which is declared in the calling function as:
char src[] = "device_id";
My confusion rests with dereferencing the src:
for(i = 0; src[i] != '\0'; i++) {
printf("src %d: [ %s ]\n", i, &src[i]);
}
...
Hello,
gcc 4.4.3 c89
I start a new c programming job in the next 4 weeks. And I want to brush up on my pointer and arrays skills for some advanced techniques. My new job requires the use of this very much.
I have been browsing the Internet for some possible questions and answers for pointer and arrays exercises. But have not really fo...
/*1*/ const char *const letter = 'A';
/*2*/ const char *const letter = "Stack Overflow";
Why is 1 invalid but 2 valid?
letter is a pointer that needs to be assigned an address. Are quoted strings addresses? I'm assuming this is why #2 is valid and that single quoted strings are not considered addresses?
Also, what is the difference...
int d() {return 0;} int i() {return 7;}
struct a { int(*b)(); }c={d};
typedef struct e{ struct a f; }g;
main() { struct e *h; h->f.b = i; }
I am getting segmentation fault when I try to run this program. Can anyone justify the reason?
And I also tried like
int d() {return 0;} int i() {return 7;}
struct a { int(*b)(); }c={d};
typ...
struct a
{
int (*ptr1)();
int (*ptr2)();
int data;
};
typedef struct
{
struct a x;
}all;
int fun1()
{
return 5;
};
int fun2()
{
return 9;
};
I can assign like
all *mem = (all*)malloc(sizeof(all));
mem->x.ptr1 = fun1;
mem->x.ptr2 = fun2;
Is there any other way to assign these function pointers?
Is it possible to assi...
The dynamic_cast operator is returning zero (0) when I apply to a pointer that points to an instance of a multiply inherited object. I don't understand why.
The hierarchy:
class Field_Interface
{
public:
virtual const std::string get_field_name(void) const = 0; // Just to make the class abstract.
};
class Record_ID_Interface
{...
When you want to return an instance from a method, do you create the object and send a pointer back, or a reference back? Whats the correct method and the method signature for this?
...
In C, when we access a[i][j] using pointers why do we need the second * in *(*(a + i) + j)? Using printf() I see a + i and *(a + i) print the same value.
...