473,549 Members | 2,568 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Converting to/from pointer

Hi Group!

I have a vector<floatvar iable that I need to pass to a function, but
the function takes a float * arguement. That's OK, I can convert by
doing &MyVector.front (), but when I get back a float * from the
function, how to convert that back to a vector?

Thanks in advance!

Jun 2 '07 #1
156 5723
Lame Duck said:
Hi Group!

I have a vector<floatvar iable that I need to pass to a function, but
the function takes a float * arguement. That's OK, I can convert by
doing &MyVector.front (), but when I get back a float * from the
function, how to convert that back to a vector?
This is a C group. Ask in comp.lang.c++.

Crossposted to that group, and followups set.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jun 2 '07 #2
Lame Duck <no****@nospam. comwrites:
I have a vector<floatvar iable that I need to pass to a function, but
the function takes a float * arguement. That's OK, I can convert by
doing &MyVector.front (), but when I get back a float * from the
function, how to convert that back to a vector?
Your question is about C++, but this newsgroup talks about C.
Try comp.lang.c++.
--
Ben Pfaff
http://benpfaff.org
Jun 2 '07 #3
Lame Duck wrote:
>
I have a vector<floatvar iable that I need to pass to a function, but
the function takes a float * arguement. That's OK, I can convert by
doing &MyVector.front (), but when I get back a float * from the
function, how to convert that back to a vector?
Comp.lang.c++ is in the next town. Try it.

--
<http://www.cs.auckland .ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfoc us.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
<http://kadaitcha.cx/vista/dogsbreakfast/index.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

Jun 2 '07 #4
Lame Duck wrote:
Hi Group!

I have a vector<floatvar iable that I need to pass to a function,
There are no such things as "vector<flo at>" in C. Post to a newsgroup
appropriate to the language you are using.
but
the function takes a float * arguement.
(Note that "argument" is this spelt. Compilers will pick nits at least
as finely as I have.)
That's OK, I can convert by
doing &MyVector.front (),
No, you can't. There are is such thing as "MyVector.front ()" in C. Post
to a newsgroup appropriate to the language you are using.
but when I get back a float * from the
function, how to convert that back to a vector?
Thanks in advance!
Bite me.
Jun 2 '07 #5
"Lame Duck" <no****@nospam. comwrote in message
Hi Group!

I have a vector<floatvar iable that I need to pass to a function, but
the function takes a float * arguement. That's OK, I can convert by
doing &MyVector.front (), but when I get back a float * from the
function, how to convert that back to a vector?
You know how many floats you have.

ptr[i] is a float, iterating with i over the array you get back.

Though it is a long time since I used C++, there will be a way of
constructing an empty vector and pushing floats into it. So simply do that.

It is huge fiddle, and illustrates one of the main problems with inventing
basic types, like structures to hold arrays of real numbers. Unless everyone
uses the type religously, it becomes a real hassle to fit pieces of code
together. The logic is usually trivial, but messy and error prone.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Jun 2 '07 #6
No, a pointer to a float is the same as an array of float. I need to
make that into a vector.
On 2 Jun 2007 at 18:30, osmium wrote:
"Richard Heathfield" wrote:
>Lame Duck said:
>>Hi Group!

I have a vector<floatvar iable that I need to pass to a function, but
the function takes a float * arguement. That's OK, I can convert by
doing &MyVector.front (), but when I get back a float * from the
function, how to convert that back to a vector?

This is a C group. Ask in comp.lang.c++.

Crossposted to that group, and followups set.

The function returns a pointer to a single float datum, right? So you want
to know how to put a float in a vector? ISTM if the function wanted to
return a vector of floats it would have *returned* a vector of floats.

Jun 2 '07 #7
Well C++ is an extension of C so no harm in asking here! Many people
know both anyways...

On 2 Jun 2007 at 18:11, Ben Pfaff wrote:
Lame Duck <no****@nospam. comwrites:
>I have a vector<floatvar iable that I need to pass to a function, but
the function takes a float * arguement. That's OK, I can convert by
doing &MyVector.front (), but when I get back a float * from the
function, how to convert that back to a vector?

Your question is about C++, but this newsgroup talks about C.
Try comp.lang.c++.
Jun 2 '07 #8
Lame Duck said:
No, a pointer to a float is the same as an array of float.
No, it isn't.
I need to make that into a vector.
C doesn't have a 'vector' type.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jun 2 '07 #9
On 2007-06-02 14:16:23 -0700, Lame Duck <no****@nospam. comsaid:
On 2 Jun 2007 at 21:01, Richard Heathfield wrote:
>Lame Duck said:
>>No, a pointer to a float is the same as an array of float.

No, it isn't.

Yes, a pointer can actually point to a whole block of float (aka array)
although in a sense it actually points to one float.
Full stop. A pointer to a float is not the same thing as an array of
float. In many circumstances, arrays are *converted* to pointers to
their initial element, but they are not the same thing.
What happens is
that really the first float and the top of the block of floats is the
same address, and that's where the pointer points.
I find it hilarious that you feel the need to tell Richard Heathfield
that. (hint, he knows full well what happens)
>
>>I need to make that into a vector.

C doesn't have a 'vector' type.

True, C++ does,
That doesn't make this any more on topic for comp.lang.c
though you can define extra types in C as structs -
infact a struct is essentially a class with no constructor or
destructor.

--
Clark S. Cox III
cl*******@gmail .com

Jun 2 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
16449
by: Joseph Suprenant | last post by:
I have an array of unsigned chars and i would like them converted to an array of ints. What is the best way to do this? Using RedHat 7.3 on an Intel Pentium 4 machine. Having trouble here, hope someone can help Thanks
4
1353
by: Eric | last post by:
See question in main function below...TIA. struct A {}; struct B: public A {}; #include <boost/shared_ptr.hpp> #include <set> typedef boost::shared_ptr<A> AP; typedef std::set<AP> AS;
2
2867
by: Richard L Rosenheim | last post by:
I'm converting some routines from C to C#. The code involves having arrays of bytes which are passed to a function as an array of longs. Well, technically the C code has a pointer to an array of char which is passed to the function which treats the pointer as a pointer to an array of longs. I would appreciate if someone could direct me to...
1
1407
by: Jason Bell | last post by:
While I'm experienced with c# and regular c++, I'm very new to managed c++ so please bare with me. Here's the scenario: I have a function that wraps a pointer to an unmanaged function. I want the wrapping function to be CLS compliant. Here's what I have now. It works perfectly, but isn't CLS compliant:
36
4435
by: kjvt | last post by:
Based on a prior posting, I've written a function to convert a recordset to a dataview. The first call to the function for a given recordset works perfectly, but the second call always returns a dataview with a count = 0. Can someone explain why and how I might work around this problem? Here is the code for my function: Public Shared...
2
1265
by: Kavya | last post by:
Since Circle is-a Shape we are allowed to do this Circle *c = new Circle; Shape *s = c; //Works But we can't do this Circle **cc = &c; Shape **ss = cc; //Does not works
3
2955
by: ASWINIGANGADHARAM | last post by:
hi all, i am studying engg,i have problem that ,how can i convet from the file pointer to character pointer or character array.in my project i cant use file pointer,i need to convert file pointer as a character pointer.please help me in this regard, thank u advance aswin
2
1663
by: lbscprogrammer | last post by:
Hi, I'm in trouble here... I need to get this program working to proceed with my application. The program is very complex, it works fine on a 10 year old system written in IBM C/2. I am showing only what I think yu may need here, please let me know if you need anything else. I am converting it to VS 7.1 (C not C++). All my source is named .C....
0
1374
by: ling2000 | last post by:
Hello all, I'm trying to upgrade a VB6 project into VB.net, and the problem I had is in converting 'address of' to 'delegate'. I had the error "Value of type 'DelegateIDccManSink_OnLogIpAddr' cannot be converted to 'integer'.", when calling this line, ReplaceVtableEntry(.., .., callbackOnLogIpAddr). I guess the problem is due to the VB6...
0
7726
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7967
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7485
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5377
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3488
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1953
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1064
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
772
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.