void pointer


 
Thread Tools Search this Thread
Top Forums Programming void pointer
# 8  
Old 06-14-2012
Quote:
Originally Posted by vlm
Actually I changed the
Code:
a[i]

to
Code:
&a[i]

and works fine.
It's still wrong. The compiler can't understand your intent here, it can only tell you when something's syntactically wrong.

If you want to pass the array element and not the array itself, that's a void *, not a void **.
# 9  
Old 06-14-2012
Quote:
Originally Posted by Corona688
It's still wrong. The compiler can't understand your intent here, it can only tell you when something's syntactically wrong.

If you want to pass the array element and not the array itself, that's a void *, not a void **.
That's strange because not only compiles fine but works as well...
So if I want to pass the whole array I have to do it the way I said before?
# 10  
Old 06-14-2012
Quote:
Originally Posted by Corona688
It's still wrong. The compiler can't understand your intent here, it can only tell you when something's syntactically wrong.

If you want to pass the array element and not the array itself, that's a void *, not a void **.
It is actually correct since &a[i] is void** not void*...unless i am not gettng your drift...
# 11  
Old 06-14-2012
Quote:
Originally Posted by vlm
That's strange because not only compiles fine but works as well...
It might help if you posted the contents of // do things

I've seen situations in C where two opposite mistakes made the code work fine. I'm still not convinced the code works quite the way you think it does.
# 12  
Old 06-14-2012
Quote:
Originally Posted by shamrock
It is actually correct since &a[i] is void** not void*...unless i am not gettng your drift...
It's syntactically correct, but that doesn't mean it's logically correct. That he's taking the array index makes me suspect he wants the content of the array, but the ampersand makes it a pointer pointer again...
# 13  
Old 06-14-2012
Quote:
Originally Posted by vlm
That's strange because not only compiles fine but works as well...
It works because you got it right...
Quote:
Originally Posted by vlm
So if I want to pass the whole array I have to do it the way I said before?
To pass whole array supply its name as argument to fun like "fun(a)"...even fun(&a[0]) works since array name "a" is a pointer to a[0]...

---------- Post updated at 03:15 PM ---------- Previous update was at 03:10 PM ----------

Quote:
Originally Posted by Corona688
It's syntactically correct, but that doesn't mean it's logically correct. That he's taking the array index makes me suspect he wants the content of the array, but the ampersand makes it a pointer pointer again...
Ah my bad Smilie since you are hinting at the semantics...
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Malloc to void pointer fails

I have a function to which I will pass a struct ID and it will return me a string. I will pass a pointer to store the name string and that pointer will be allocated memory by the function called. int ConvertIDToName(void *id, void *name, size_t *size) { int status = 0; ... (5 Replies)
Discussion started by: rupeshkp728
5 Replies

2. HP-UX

converting void pointer to pthread_t on HPUX Itanium

i am trying to convert void pointer to pthread_t on hpux-itanium 64 bit which fails as below "src/file.cpp", line 88: error #2171: invalid type conversion pthread_t tid = reinterpret_cast<pthread_t>(m_threadId); 1 error detected in the compilation of "src/file.cpp" ... (0 Replies)
Discussion started by: skyineyes
0 Replies

3. Shell Programming and Scripting

Eliminate double void line

Hi, I need to eliminate each second void line in a text file. novus MILLENNIO ineo frater in episcopatus , presbyter et diacon|diaconus , (1 Reply)
Discussion started by: mjomba
1 Replies

4. Programming

functions that manipulate void pointers

I have two or more linked lists that have the same names for their "next". For example, struct server_t { sockaddr_in * sin; server_t * next_; } struct player_t { char name; player_t * next_; } How can I get a function to take in either type and manipulate the pointers? I... (3 Replies)
Discussion started by: pyramation
3 Replies

5. Programming

pass a pointer-to-pointer, or return a pointer?

If one wants to get a start address of a array or a string or a block of memory via a function, there are at least two methods to achieve it: (1) one is to pass a pointer-to-pointer parameter, like: int my_malloc(int size, char **pmem) { *pmem=(char *)malloc(size); if(*pmem==NULL)... (11 Replies)
Discussion started by: aaronwong
11 Replies

6. UNIX for Dummies Questions & Answers

void (char *asd)

void asdf(char *asd) is this thing a pointer? (1 Reply)
Discussion started by: khestoi
1 Replies

7. Programming

What is the difference between f(...), f(void) and f()

What is the difference between f(...) , f(void),f() I know that f(void) doesn't take any parameters, but what about f() and f(...) Does the last call of function even exists? (2 Replies)
Discussion started by: purplelightspar
2 Replies

8. Programming

How to return void function pointer

Hello all im trying to build function that will return void function pointer what is mean is ( not working ) the main function void * myClass::getFunction(int type){ if(type==1) return &myClass::Test1; if(type==2) return &myClass::Test2; } void myClass::Test1(){... (1 Reply)
Discussion started by: umen
1 Replies

9. Shell Programming and Scripting

Sorting the Void File in CSH

First and foremost, this is not a homework for your information. I'm just new to using c-shell programming and I just wanted to make my life easier @ work. Say, the file contains the following: ID FILE NO. SL VP 1 1 22 33 1 2 ... (3 Replies)
Discussion started by: ilak1008
3 Replies
Login or Register to Ask a Question