LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Giving back a pointer from a function (C99/CVI9.01)

hi all,

I asked this some weeks ago and need to ask it ones more.

Using CVI 9.01 with C99 I make sometimes (!!!) - not everytime- the following observation if I want to give a pointer to a fct and the function has to vary this pointer:

//Declaration of the fct
void fct(int**);

//This runs...
int* p;
p=0;
fct(&p);
printf("%p\n",p); //Result: "0" ?????

//Implementation of the function
void fct(&p)
{
*p=123;
//(*p)=123; does the job ???
}

Any idea ?

best regards

Simon
0 Kudos
Message 1 of 17
(3,588 Views)

Can you confirm the lines of your code where you show fct()? The forward declaration does not match the later definition, which my compiler also rejects.

 

JR

0 Kudos
Message 2 of 17
(3,584 Views)
JR,

sorry, this was a mistake. I wrote it down without testing it. the function should look like this:

void fct(int** pp)
{
*pp=123;
//(*pp)=123; does the job ???
}

simon
0 Kudos
Message 3 of 17
(3,582 Views)

Well you are using some pointers, but you don't appear to actually have any object declared to which your pointers can point. I needed to use a (int *) cast on the 123 to persuade the compiler to compile the code. You also seem to have a strange type character in your printf specification: %p. Is this also a typo?

 

JR

0 Kudos
Message 4 of 17
(3,577 Views)
JR,

yes, I forgot - you have to cast the int into a int*. I did this in my code. The "%p" is the placeholder of a pointer in the printf()-family.
0 Kudos
Message 5 of 17
(3,570 Views)
i've been doing that kind of thing (passing pointers to pointers as function arguments) since a long time with CVI and i never had any problem with it. the example you gave seem totally valid to me, may the problem lies elsewhere in your code ? can you give us a more complete (and correct) code which displays the strange behavior you seem to have ?
0 Kudos
Message 6 of 17
(3,546 Views)
hi all,

it makes no sense to send more code, the problem must lay in the project-organiszation. since CV9.0/C99 I have from time to time this behaviour:

-->the pointers are not given correctly out of functions (look above)
-->the malloc()-functions are not working correctly, they give back no NULL, but the objects are making trouble
-->the commandline - arguments shown have other values then are working, maybe the IDE shows 2, but a switch(arg) is working with "case 3:"

Often the trouble begins, if I #include"*.h" in another of my declaration-files because I need this definition in another struct-declaration now. then A is not known in B and so on - you know this. If I have "touched" many files and modified inside them suddenly it works again.

E.g. my project where I had these problems some days ago now runs ok without changing any code. Is there a possibility to make a "clean" in the project before building it new. Or: what directories are to delete to make such a "clean" by hand ?

best regards

Simon

P.S.: I know, it sounds creazy, but I'm not a beginner and have not drunken beer.
0 Kudos
Message 7 of 17
(3,529 Views)

Hello - 

 

I have also tried to reproduce the behavior you have mentioned, and have not been able to.  I would be quick to doubt your claims, as passing pointers into functions is such a standard C operation that it seems we would have heard many more complaints if it were an issue.  However, ever since you blew our minds with this screenshot - I have no problem believing you're seeing some strange things. 

 

To answer your question, one way to force a rebuild is to select "Mark Project for Compilation" from the build menu, or to manually delete the cvibuild.<projectname> directory.

 

We would really like to be able to put a finger on the corruption that is apparently happening in your binary.  If there was any chance we could run your project and see the behavior you've reported, we would really appreciate it.  You could zip it up and put it on ftp://ftp.ni.com/incoming (behind our firewall, allowing only NI employees to access the files).

 

NickB

National Instruments  

0 Kudos
Message 8 of 17
(3,526 Views)
nick,

ok, it will be the best: if the next time these things occure, I will transfer it on the ftp.

thanks and best regards

Simon
0 Kudos
Message 9 of 17
(3,520 Views)

Sounds good Simon -

 

Just reply back to this post with the name of the file you've uploaded, and I'll take a look.

 

NickB

National Instruments 

0 Kudos
Message 10 of 17
(3,516 Views)