2
голосов
10ответов
5281 просмотров

What arguments does the sizeof operator take in C?

[Original title referred to 'sizeof function'.] I tried these and they all worked: char *p; printf("Size of *p is %d\n",sizeof(*p)); //result =1 printf("Size of p is %d\n",sizeof( p)); //result =4 printf("Size of p is %d\n",sizeof(&p)); //result =4 I wonder why the first printf is ...

0
голосов
1ответов
395 просмотров

Pointers for data returned by delegate methods in MacRuby

I'm working on a small MacRuby project, using 0.5b1, which is implementing the delegate methods required for Growl (the app is using Growl for notifications). I would like to be able to respond to the Growl callbacks when the notification is clicked, however when you register the Growl delegate ...

1
голосов
3ответов
1561 просмотров

Meaning of "@far int* @near IntegerPointer;"

I have the following definition. far int* near IntegerPointer; Does this mean, a pointer placed in 'near' memory pointing to a integer placed in far memory area. Can anyone please clarify.

37
голосов
5ответов
27631 просмотров

Create new C++ object at specific memory address?

Is it possible in C++ to create a new object at a specific memory location? I have a block of shared memory in which I would like to create an object. Is this possible?

0
голосов
3ответов
119 просмотров

Why can't the Nodes be linked together?

EDIT: Is it possible to NOT use new? (do not dynamically allocating memory) I think it is push that is wrong, but I don't know where, how, and why. here is the code: struct Node { string fileName; Node *link; }; int size(Node *&flist) { int count = 0; Node *tempPtr = flist; ...

0
голосов
3ответов
6459 просмотров

In C++, how do I push an object to a vector while maintaining a pointer to the object?

In my code, I have a vector of Student objects. vector<Student> m_students; I want to: Check to see if the vector contains any Student of a certain name. If no such Student exists, add a new one. Add data to the Student of that name. Consider the following code: // Check to see if t...

1
голосов
3ответов
12656 просмотров

return a list<int> from a function c++</int>

Every time I try to use my add function and return a list from it. I get an undefined symbol error. What am I doing wrong here. this is the error: Undefined first referenced symbol in file add(std::list&lt;int, std::allocator&lt;int&gt; &gt; c...

0
голосов
3ответов
236 просмотров

Why is this string changed?

I have the following code, so far, I want to check if a file name is already in the linked list fileList (or flist). according to the output, the string saved in the first Node was changed somewhere in Node* getFileName(Node *&amp;flist) How did this happen? Also, is there anything else that I'm ...

0
голосов
4ответов
10464 просмотров

How to use string and string pointers in C++

I am very confused about when to use string (char) and when to use string pointers (char pointers) in C++. Here are two questions I'm having. which one of the following two is correct? string subString; subString = anotherString.sub(9); string *subString; subString = &amp;anotherString.sub(9); ...

4
голосов
5ответов
601 просмотров

What does this notation mean in C?

int *w; int **d; d = &amp;w; What does the **d store exactly?

5
голосов
2ответов
11685 просмотров

How to cast an int's address to char pointer in C?

Currently the below code gives me a warning when i try to compile it: int z; char *w; w = &amp;z; How can i cast &amp;z properly so that w stores the pointer to z's address?

8
голосов
6ответов
1299 просмотров

What's the difference between *d++ and (*d)++ in C?

as in the title, what's the difference because these two seem to get me the same results?

2
голосов
3ответов
1148 просмотров

Pointer to class method

I'm trying to have pointer to class methods, so I have something like: class foo { public: static void bar() { } }; void (foo::*bar)() = &amp;foo::bar; That doesn't compile :( I get: &gt; error: cannot convert ‘void (*)()’ to &gt; ‘void (foo::*)()’ in &gt; initialization

0
голосов
7ответов
258 просмотров

pointers and references question

#ifndef DELETE #define DELETE(var) delete var, var = NULL #endif using namespace std; class Teste { private: Teste *_Z; public: Teste(){ AnyNum = 5; _Z = NULL; } ~Teste(){ if (_Z != NULL) DELETE(_Z); } Teste *Z(){ ...

35
голосов
6ответов
54082 просмотров

C typedef of pointer to structure

I had come across the following code: typedef struct { double x; double y; double z; } *vector; Is this a valid type definition? The code compiles and runs fine. I was just curious if this is common practice.

2
голосов
2ответов
756 просмотров

Is it possible for slicing to occur with Smart Pointers?

If I understand slicing correctly I don't think this could happen with pointers or smart pointers. For example, if you had: class A { int something; }; class B : public A { int stuff; int morestuff; }; int main() { std::shared_ptr&lt;B&gt; b(new B()); std::shared_ptr&lt;A&gt; a; a ...

2
голосов
4ответов
1166 просмотров

Java references values are addresses values?

When I do: int x[] = new int[2]; System.out.println("...&gt; " + x); the output value is like this: [[email protected] so that hex number is concerning to the memory address where the object has been allocated? and [I what does it meaning?

1
голосов
3ответов
2930 просмотров

How to dereference a pointer passed by reference in c++?

I'm doing (something like) this: void insert(Node*&amp; node, string val, Node* parent) { if (node == NULL) instantiateNode(node, val, parent); else insert(node-&gt;child, val, node); } The thing is, that instantiateNode(..., parent) seems to modify the original *&amp;node pass...

2
голосов
5ответов
7234 просмотров

What does (int **array;) create?

I want to know what is happening in memory when you declare: int **array;

0
голосов
2ответов
296 просмотров

What are some techniques to safely handle both 32bit and 64bit pointers without a conditional macro?

I'm updating some code in a library because i've found out my original code assumed 32bit pointers. I have my own thinkings on how to fix it, but for thoroughness, I want to ask what are some techniques you would use to make this code work for both 32bit and 64bit without a macro? char *argList...

0
голосов
3ответов
3952 просмотров

delphi - how to use declare and use pointer to the const array in a const record?

I have a few const arrays of the same base type but different sizes, and I need to point to them in the const records. The code below compiles successfully, but finishes with error. type Toffsets = array of integer; Trec = record point1: Tpoint; //complete size ...

7
голосов
8ответов
5342 просмотров

Why are pointers and recursion looked upon as a complicated issues?

Recently I was reading about Article on Interviewing an Software Engineering Position by Joel and he mentioned about asking candidate about Recursion and Pointer's after some simple puzzles. I wonder why Pointers and Recursion are considered to be complicated Issues ? Update: What can be done ...

8
голосов
9ответов
1602 просмотров

How do you program safely outside of a managed code environment?

If you are someone who programs in C or C++, without the managed-language benefits of memory management, type checking or buffer overrun protection, using pointer arithmetic, how do you make sure that your programs are safe? Do you use a lot of unit tests, or are you just a cautious coder? Do y...

2
голосов
4ответов
1110 просмотров

Access a function pointer without parenthesis

I have this code: #include &lt;stdio.h&gt; int getAns(void); int num; int main() { int (*current_ans)(void); current_ans = &amp;getAns; // HERE printf("%d", current_ans()); } int getAns() { return num + 3; } However, is it possible to have something in the // HERE ...

1
голосов
4ответов
464 просмотров

C - If/Else and Pointers Returning Wrong String

We have a function longest, which returns the longest substring that consists of letters. Example: longest("112****hel 5454lllllo454") would return: lllllo However, when I run the program it seems to return lllllo454. Here is the function: char *longest(char *s){ char *pMax = NULL; i...

0
голосов
4ответов
320 просмотров

Using a variable to represent a function in C

This has the functionality I want (and it works) #include &lt;stdio.h&gt; //includes other libraries needed int foo(); int main() { while(true) { while(foo()==1) { //do something } //does other unrelated things } } int foo() { ...

1
голосов
7ответов
279 просмотров

Creating pointer-to-pointer using malloc

The code is char** p = (char **) malloc(sizeof(char **) * size); //Where size is some valid value. p[1] = (char*) malloc(sizeof(char) * 30); Is the above code fine? My understanding is p -&gt; +---------+ 0 char* + -&gt; {c,o,d,e,char** p = (char **) malloc(sizeof(char *) * size); } ...

6
голосов
6ответов
693 просмотров

Why am I able to make a function call using an invalid class pointer

In below code snippet, although pointer is not initialized the call is still made successfully temp *ptr; ptr-&gt;func2(); Is it due to C++ language property, or it is VC++6 compiler which is foul playing? class temp { public: temp():a(9){} int&amp; func1() { return a; ...

20
голосов
10ответов
64343 просмотров

Store an int in a char array?

I want to store a 4-byte int in a char array... such that the first 4 locations of the char array are the 4 bytes of the int. Then, I want to pull the int back out of the array... Also, bonus points if someone can give me code for doing this in a loop... IE writing like 8 ints into a 32 byte ar...

0
голосов
7ответов
4024 просмотров

traversing a singly linked list in C++

I was wondering if it is possible to traverse a linked list like this: currentNode = randomNode;//where randomNode may or may not = firstNode prevNode = firstNode; while(prevNode != currentNode &amp;&amp; prevNode-&gt;link != currentNode) { prevNode = prevNode-&gt;link; } Is it possible t...