473,695 Members | 2,227 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
156 5836
Ian Collins wrote:
CBFalconer wrote:
>Richard Tobin wrote:
>>Richard <rg****@gmail.c omwrote:

If it started out as an extension then what is it now? An
extensions of the extension? ......
An "extended subset" perhaps, which of course covers everything.
No it isn't.

Yes, it is. It is an extension of the subset of C that is legal C++.
It is also an extension of the subset of Fortran that is legal C++.
Indeed, it is an extension of the subset of Tibetan that is legal C++.
Congratulations on one of the most vacuous utterances ever written.

Jun 3 '07 #31
Martin Ambuhl wrote:
Ian Collins wrote:
>CBFalconer wrote:
>>Richard Tobin wrote:
Richard <rg****@gmail.c omwrote:

If it started out as an extension then what is it now? An
extension s of the extension? ......
An "extended subset" perhaps, which of course covers everything.
No it isn't.

Yes, it is. It is an extension of the subset of C that is legal C++.

It is also an extension of the subset of Fortran that is legal C++.
Indeed, it is an extension of the subset of Tibetan that is legal C++.
Congratulations on one of the most vacuous utterances ever written.
Did you read Richard Tobin's comment?

--
Ian Collins.
Jun 3 '07 #32
Martin Ambuhl <ma*****@earthl ink.netwrites:
Ian Collins wrote:
>CBFalconer wrote:
>>Richard Tobin wrote:
Richard <rg****@gmail.c omwrote:

If it started out as an extension then what is it now? An
extension s of the extension? ......
An "extended subset" perhaps, which of course covers everything.
No it isn't.
Yes, it is. It is an extension of the subset of C that is legal C++.

It is also an extension of the subset of Fortran that is legal
C++. Indeed, it is an extension of the subset of Tibetan that is legal
C++. Congratulations on one of the most vacuous utterances ever
written.
Which he already explictly acknowledged with the phrase "which of
course covers everything".

(And since the subset of C that is legal C++ is a very large fraction
of C, it's hardly vacuous in this particular case.)

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 3 '07 #33
I really find it hard to understand the bile and negativity that seems
to be this Group's bread and butter! I've read any number of Groups and
Forums and by and large they're all pretty friendly places, but here all
I've got is a torrent of abuse!
>>That's OK, I can convert by
doing &MyVector.front (),

No, you can't. There are is such thing as "MyVector.front ()" in C.

Don't give up so easily!

void private(void) {
extern int class(void);
struct new {
int new;
int delete;
int (*front)(void);
} MyVector = ( 1, 2, class }; // <<--- did you mean { not (
???
int cin = 42;
int cout = cin

&MyVector.front (),

-1;
}

Perfectly legal C, reproducing the Lame Duck's construct right
down to the ampersand and comma. It might be criticized on
stylistic grounds, but, hey ...
I really don't understand what this code is doing! I think you
misunderstood my question - &MyVector.front () already works, the problem
is to convert pointer/array to vector without having to copy all data by
hand.

Jun 3 '07 #34
On 2 Jun 2007 at 21:42, Ben Pfaff wrote:
Lame Duck <no****@nospam. comwrites:
>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. 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.

It is true that there is a close relationship between arrays and
pointers in C (and C++). But it is incorrect to claim that a
pointer to a float and an array of float are the same thing. The
C FAQ has a whole category of questions and answers on this topic
(section 6, "Arrays and Pointers").
OK, maybe in C there's some subtelty that I haven't worked out, but
definitely in C++ - one of the main "soundbite to remember" in my C++
class was "an array is just the same thing as a constant pointer".
>>>
C doesn't have a 'vector' type.

True, C++ does, though you can define extra types in C as structs -
infact a struct is essentially a class with no constructor or
destructor.

You seem to have become confused about what language you are
talking about. Your statement is not true in C, as a C struct is
not a class with no constructor or destructor: C doesn't have
classes or constructors or destructors, so the statement is
meaningless. Your statement is also not true in C++, as a C++
struct can have constructors and a destructor.
What I meant was: a C struct is like a C++ class without a constructor
or destructor.

Jun 3 '07 #35
Lame Duck said:
I really find it hard to understand the bile and negativity that seems
to be this Group's bread and butter!
You didn't get any bile from me. You got a polite request to take your
discussion to a group where it's relevant.
I've read any number of Groups
and Forums and by and large they're all pretty friendly places,
I'm friendly places too, but clc is about C, not C++.
but here all I've got is a torrent of abuse!
No, you got a polite request to take your discussion to a group where
it's relevant. Polite requests don't count as abuse.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jun 3 '07 #36
Lame Duck said:
On 2 Jun 2007 at 21:42, Ben Pfaff wrote:
<snip>
>It is true that there is a close relationship between arrays and
pointers in C (and C++). But it is incorrect to claim that a
pointer to a float and an array of float are the same thing. The
C FAQ has a whole category of questions and answers on this topic
(section 6, "Arrays and Pointers").

OK, maybe in C there's some subtelty that I haven't worked out, but
definitely in C++ - one of the main "soundbite to remember" in my C++
class was "an array is just the same thing as a constant pointer".
Well, that's wrong in C++ as well as in C. In C++, an array is *not*
just the same thing as a constant pointer. Your teacher was wrong.

<snip>
What I meant was: a C struct is like a C++ class without a constructor
or destructor.
No, it isn't. There are quite a few differences between C structs and
C++ classes. Indeed, there are quite a few differences between C
structs and C++ structs.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jun 3 '07 #37
Lame Duck wrote:
On 2 Jun 2007 at 21:42, Ben Pfaff wrote:
>Lame Duck <no****@nospam. comwrites:
>>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. 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.
It is true that there is a close relationship between arrays and
pointers in C (and C++). But it is incorrect to claim that a
pointer to a float and an array of float are the same thing. The
C FAQ has a whole category of questions and answers on this topic
(section 6, "Arrays and Pointers").

OK, maybe in C there's some subtelty that I haven't worked out, but
definitely in C++ - one of the main "soundbite to remember" in my C++
class was "an array is just the same thing as a constant pointer".
Read the FAQ entry, it applies to C++ as much as to C.

--
Ian Collins.
Jun 3 '07 #38
"Lame Duck" <no****@nospam. comwrote in message
>
I really find it hard to understand the bile and negativity that seems
to be this Group's bread and butter! I've read any number of Groups and
Forums and by and large they're all pretty friendly places, but here all
I've got is a torrent of abuse!
We hate C++ here because it is runing our nice language.
I just installed Java on my new Vista machine. Something actually works! It
is such a clean any easy way to get graphics up and running compared with
trying to get C sharp, C++, C++ with funny Chinese hats, or whatever, to
work. Java is a much better way to go if you want object-orientation.

Evil Microsoft have even broken C. When I tried to compile some portable
modules for a graphical app, the compiler complained about the unsafe
function strcpy(). Bye bye ANSI C, I suppose.
>
I really don't understand what this code is doing! I think you
misunderstood my question - &MyVector.front () already works, the
problem is to convert pointer/array to vector without having to copy all
data
by hand.
By hand? I know C++ is bad, but surely not.
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Jun 3 '07 #39
"Lame Duck" <no****@nospam. comwrote
>
What I meant was: a C struct is like a C++ class without a constructor
or destructor.
Kind of. It very helpful to know C if youa re trying to understand why C++
is the way it is.
C structs lay out variables contiguously in memory. C++ classes extend that
idea to tie functions to the data types they operate on then, and this is
the clever part, express relationships between different functions and data
types.

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

Jun 3 '07 #40

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

Similar topics

4
16461
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
1357
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
2874
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 an example, article, etc. that discuss how to convert such code to C#. TIA,
1
1412
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
4469
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 Function GetViewFromRS(ByVal pRS As ADODB.Recordset) _ As DataView
2
1271
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
2960
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
1666
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. No compile errors, but it throws an exception at runtime. Here is the structure and the code...
0
1380
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 expected a memory address, but the 'delegate' doesn't return an address. Any ideas are appreciated.
0
8638
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8578
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8998
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8857
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8831
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6494
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4346
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2278
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1979
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.