473,414 Members | 1,988 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Converting to/from pointer

Hi Group!

I have a vector<floatvariable 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 5686
Lame Duck said:
Hi Group!

I have a vector<floatvariable 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<floatvariable 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<floatvariable 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.securityfocus.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<floatvariable that I need to pass to a function,
There are no such things as "vector<float>" 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<floatvariable 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<floatvariable 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<floatvariable 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 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.
>I need to make that into a vector.

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.

Jun 2 '07 #10
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 #11
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").
>>I need to make that into a vector.

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.
--
Ben Pfaff
http://benpfaff.org
Jun 2 '07 #12
Lame Duck wrote:
Well C++ is an extension of C so no harm in asking here! Many people
know both anyways...
C++ and C are different languages. They have different syntax. They
have different semantics. They have different libraries. The only real
harm from what you wrote above is that it makes it author appear a fool.
Jun 2 '07 #13
Lame Duck wrote:
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.
Many of the questions in Section 6 of the comp.lang.c
Frequently Asked Questions (FAQ) list http://c-faq.com/ are
devoted to explaining why you are wrong, R-O-N-G, wrong.

If you would like to explain the finer points of C to
the FAQ maintainer so he can correct this blunder that is
so clear to you, you may be able to make some money by
selling tickets to the debate. I'm sure I'm not the only
one who could use a good laugh.

--
Eric Sosman
es*****@acm-dot-org.invalid
Jun 2 '07 #14
Lame Duck wrote, On 02/06/07 21:41:
Well C++ is an extension of C
No it isn't. It might have started out that way but that is not what it
is now.
so no harm in asking here!
Yes there is. You've reduced your chances of getting help drastically.

In any case, a lot of people here probably know about a lot of other
things that are not topical here, that does not make this an appropriate
place to ask about car maintenance, soldering or lots of other things.
Many people
know both anyways...
Since those that know both and hang out in both groups may well now
decide not to help you even if you post to the correct group.
On 2 Jun 2007 at 18:11, Ben Pfaff wrote:
Please don't top post. Your reply belongs after or interspersed with the
text you are replying to. See the posts you replied to, this post, and
in fact most of the rest of the posts on this group for examples.
--
Flash Gordon
Jun 2 '07 #15
Martin Ambuhl wrote:
Lame Duck wrote:
>Hi Group!

I have a vector<floatvariable that I need to pass to a function,

There are no such things as "vector<float>" 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.
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 };
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 ...

--
Eric Sosman
es*****@acm-dot-org.invalid
Jun 2 '07 #16
Clark Cox <cl*******@gmail.comwrites:
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)
Why? The poster, while wrong, doesn't know who or what Richard
Heathfield is.
Jun 2 '07 #17
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.
A pointer is not an array. An array is not a pointer.

Read section 6 of the comp.lang.c FAQ, <http://www.c-faq.com/>.
>>I need to make that into a vector.

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.
Once again, you were asking about vectors. C doesn't have vectors.
C++ does. Questions about vectors belong in comp.lang.c++, not in
comp.lang.c.

Why are you still here? I mean, if you wanted to talk about C, you'd
be in the right place, but in that case I'd suggest starting a new
thread.

(I see that this discussion is inappropriately cross-posted to
comp.lang.c and comp.lang.c++. Richard Heathfield *tried* to redirect
followups to comp.lang.c++, but somebody overrode that. Followups
redirected again.)

--
Keith Thompson (The_Other_Keith) 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 2 '07 #18
Lame Duck <no****@nospam.comwrites:
Well C++ is an extension of C so no harm in asking here! Many people
know both anyways...
Wrong. C and C++ are two different languages, and questions about C++
are *not welcome* in comp.lang.c.

And please don't top-post; see the following links:

http://www.caliburn.nl/topposting.html
http://www.cpax.org.uk/prg/writings/topposting.php

Followups redirected, since this is no longer about C *or* C++.

--
Keith Thompson (The_Other_Keith) 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 2 '07 #19
Flash Gordon <sp**@flash-gordon.me.ukwrites:
Lame Duck wrote, On 02/06/07 21:41:
>Well C++ is an extension of C

No it isn't. It might have started out that way but that is not what
it is now.
If it started out as an extension then what is it now? An extensions of
the extension? ......
Jun 2 '07 #20
On Sun, 03 Jun 2007 00:07:36 +0200, in comp.lang.c , Richard
<rg****@gmail.comwrote:
>I find it hilarious that you feel the need to tell Richard Heathfield
that. (hint, he knows full well what happens)

Why? The poster, while wrong, doesn't know who or what Richard
Heathfield is.
True, but if they had followed usenet etiquette and lurked, or had
googled his name, they'd have a fair idea that he probably knows a
/lot/ more than the OP about C ....
http://www.google.co.uk/search?q=richard+heathfield

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Jun 2 '07 #21
In article <87************@gmail.com>, Richard <rg****@gmail.comwrote:
>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...

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Jun 2 '07 #22
Mark McIntyre <ma**********@spamcop.netwrites:
On Sun, 03 Jun 2007 00:07:36 +0200, in comp.lang.c , Richard
<rg****@gmail.comwrote:
>>I find it hilarious that you feel the need to tell Richard Heathfield
that. (hint, he knows full well what happens)

Why? The poster, while wrong, doesn't know who or what Richard
Heathfield is.

True, but if they had followed usenet etiquette and lurked, or had
googled his name, they'd have a fair idea that he probably knows a
/lot/ more than the OP about C ....
http://www.google.co.uk/search?q=richard+heathfield
So, you think a poster should search up the name of everyone he replies
too? I don't think so somehow.

I would point out that while he was wrong, the OP was neither rude nor
disrespectful. A polite correction is far more valid than a lecturing on
how great one might think Richard Heathfield or another regular is.

Jun 2 '07 #23
Richard wrote, On 02/06/07 23:21:
Flash Gordon <sp**@flash-gordon.me.ukwrites:
>Lame Duck wrote, On 02/06/07 21:41:
>>Well C++ is an extension of C
No it isn't. It might have started out that way but that is not what
it is now.

If it started out as an extension then what is it now? An extensions of
the extension? ......
Well, it could be an example of divergent evolution. If you want to
discus it go over to comp.lang.c++ where C++ is topical.

Follow-ups set.
--
Flash Gordon
Jun 3 '07 #24
Flash Gordon <sp**@flash-gordon.me.ukwrites:
Richard wrote, On 02/06/07 23:21:
>Flash Gordon <sp**@flash-gordon.me.ukwrites:
>>Lame Duck wrote, On 02/06/07 21:41:
Well C++ is an extension of C
No it isn't. It might have started out that way but that is not what
it is now.

If it started out as an extension then what is it now? An extensions of
the extension? ......

Well, it could be an example of divergent evolution. If you want to
discus it go over to comp.lang.c++ where C++ is topical.
This is called a divergent thread. If you wish to ignore it then please
do. But while the link between C and C++ is being discussed it is
reasonably on topic and I'm quite sure anyone discussing does not need
your permission or re-directions to other newsgroups - especially when
the C++ one would be as "on or off topic" as the C one when one
considers BOTH languages are being discussed.
Jun 3 '07 #25
On 2007-06-02 15:07:36 -0700, Richard <rg****@gmail.comsaid:
Clark Cox <cl*******@gmail.comwrites:
>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)

Why? The poster, while wrong, doesn't know who or what Richard
Heathfield is.
Perhaps a smiley was in order, but I was merely point out that I found
that fact amusing.

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

Jun 3 '07 #26
Richard Tobin wrote:
Richard <rg****@gmail.comwrote:
>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. Try using the identifiers new, class, namespace, for
example, in a C program compiled via C++. It has grown into a
language of itself. That is one reason it has its own standard.
Try using malloc without casting. etc. etc. etc.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.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 3 '07 #27
Richard wrote:
Mark McIntyre <ma**********@spamcop.netwrites:
.... snip ...
>>
True, but if they had followed usenet etiquette and lurked, or had
googled his name, they'd have a fair idea that he probably knows a
/lot/ more than the OP about C ....
.... snip ...
>
So, you think a poster should search up the name of everyone he
replies too? I don't think so somehow.

I would point out that while he was wrong, the OP was neither rude
nor disrespectful. A polite correction is far more valid than a
lecturing on how great one might think Richard Heathfield or
another regular is.
However, if he had followed Usenet practice, and lurked for a while
before disturbing by posting, he would have a good idea.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.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 3 '07 #28
Eric Sosman wrote:
Lame Duck wrote:
>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.

Many of the questions in Section 6 of the comp.lang.c
Frequently Asked Questions (FAQ) list http://c-faq.com/ are
devoted to explaining why you are wrong, R-O-N-G, wrong.

If you would like to explain the finer points of C to
the FAQ maintainer so he can correct this blunder that is
so clear to you, you may be able to make some money by
selling tickets to the debate. I'm sure I'm not the only
one who could use a good laugh.
Maybe he would be better convinced by an example. Some use of
'sizeof' is probably warrented, as is use of functions outside
main. I am too lazy at the moment to generate that example.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.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 3 '07 #29
CBFalconer wrote:
Richard Tobin wrote:
>Richard <rg****@gmail.comwrote:
>>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++.

--
Ian Collins.
Jun 3 '07 #30
Ian Collins wrote:
CBFalconer wrote:
>Richard Tobin wrote:
>>Richard <rg****@gmail.comwrote:

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.comwrote:

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.
Did you read Richard Tobin's comment?

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

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.
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_Keith) 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
Lame Duck <no****@nospam.comwrites:
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!
It is a strange group is comp.lang.c. far more "hostile" than the c++
equivalent too. While keeping "on topic" is valuable, there seems to be
a feeding frenzy in here amongst 9 or 10 posters who cant wait to get in
first with their warnings. I've counted about 7 "Off topic" warnings to
one post from the "usual suspects" either though each one knew another
would post the same warning.

Never quite understood it myself.
Jun 3 '07 #41

"Lame Duck" <no****@nospam.comha scritto nel messaggio
news:sl*******************@nospam.com...
Well C++ is an extension of C so no harm in asking here! Many people
know both anyways...
If we agreed with you, comp.lang.c++ would have never been created.
And FYI C++ isn't completely a superset of C, see:
http://www.research.att.com/~bs/bs_faq.html#C-is-subset
Jun 3 '07 #42

"Lame Duck" <no****@nospam.comha scritto nel messaggio
news:sl*******************@nospam.com...
No, a pointer to a float is the same as an array of float.
#include <stdio.h>
int main(void)
{
float array[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
float *pointer = array;

printf("%lu %lu\n", sizeof array, sizeof pointer);
return 0;
}

Displays "40 4" on my system. So? They're the same but one is ten times
bigger? :-)
Jun 3 '07 #43

"Martin Ambuhl" <ma*****@earthlink.netha scritto nel messaggio
news:5c*************@mid.individual.net...
Ian Collins wrote:
>CBFalconer wrote:
>>Richard Tobin wrote:
Richard <rg****@gmail.comwrote:

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.
At least, the subset of C that is legal C++ is larger than the
subset of Tibetan that is legal C++. (And so is the subset of Latin
which is legal (whatever it means) Italian.) Bjourne Stroustrup
claims that every example in K&R2 is valid C++.

(But the sentence above is still silly.)
Jun 3 '07 #44
Lame Duck wrote:
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".
That is wrong in both C++ and C. Either your instructor was grossly in
error or you misunderstood.

Jun 3 '07 #45
On Sun, 3 Jun 2007 17:09:08 +0200, "Army1987" <pl********@for.it>
wrote:
>
"Lame Duck" <no****@nospam.comha scritto nel messaggio
news:sl*******************@nospam.com...
>No, a pointer to a float is the same as an array of float.

#include <stdio.h>
int main(void)
{
float array[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
float *pointer = array;

printf("%lu %lu\n", sizeof array, sizeof pointer);
It would be better to cast the last two arguments so someone whose
system did not #define size_t as unsigned long would not invoke
undefined behavior.
return 0;
}

Displays "40 4" on my system. So? They're the same but one is ten times
bigger? :-)
At least now we know what the original poster meant by superset.
Remove del for email
Jun 3 '07 #46

"Army1987" <pl********@for.itwrote in message
news:f3**********@tdi.cu.mi.it...
>
"Lame Duck" <no****@nospam.comha scritto nel messaggio
news:sl*******************@nospam.com...
>No, a pointer to a float is the same as an array of float.

#include <stdio.h>
int main(void)
{
float array[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
float *pointer = array;

printf("%lu %lu\n", sizeof array, sizeof pointer);
return 0;
}

Displays "40 4" on my system. So? They're the same but one is ten times
bigger? :-)
So there's a bug in the standard that breaks array pointer equivalence? It
happens to even the best languages.
Deprectate sizeof( object) and only allow sizeof(type) and the pro
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm
blem is fixed.

Jun 3 '07 #47
Lame Duck <no****@nospam.comwrites:
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!
You have been advised repeatedly, and in many cases quite politely,
that your question is about C++, not about C, and that you should post
it in comp.lang.c++, not in comp.lang.c. And yet you persist in
posting to comp.lang.c.

You are being rude. It's not surprising that some people here in
comp.lang.c are rude to you in response. There *may* have been some
overreaction; I suggest you ignore it and move on.

It should be obvious by now that you're *not* going to get any useful
responses from comp.lang.c. I don't know what you expect to
accomplish by continuing to post here.

[...]
> 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.
Don't worry about understanding the code; the author was being
sarcastic. He was *pretending* that your question is a valid question
about C (it must have been, since you posted it to comp.lang.c).
Since C doesn't have "vectors", he invented a set of C declarations
for which "&MyVector.front()" would be valid C. The fact that the
resulting code doesn't address your problem is a result of your
posting your question to the wrong newsgroup. (He sprinkled the code
with C++ keywords used as identifiers, guaranteeing that it's not
valid C++, just to emphasize the point.)

Incidentally, I can't tell who wrote the code because you deleted the
attribution lines. Please don't do that.

Your real question, I think, is how to copy the contents of an array
into a C++ vector without copying each element individually. (I don't
know the answer to that, since I'm not sufficiently familiar with C++.
It may well be that the best solution is to copy the elements one at a
time in a loop. Or perhaps std::vector provides an operation to do
what you want in one fell swoop, though such an operation probably
works internally by looping over the elements.) You should ask *that*
question, and you should ask it in comp.lang.c++, where it's perfectly
topical. You'll probably get numerous excellent and well-informed
answers. You might even get some good advice on how to re-structure
your code so the operation you're looking for isn't needed in the
first place.

I suggest starting a new thread in comp.lang.c++, since this one's
signal-to-noise ratio has degraded considerably.

Or you can continue to waste everyone's time by whining about how rude
we've been to you. It's up to you.

--
Keith Thompson (The_Other_Keith) 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 #48
On Jun 3, 1:00 am, Mark McIntyre <markmcint...@spamcop.netwrote:
On Sun, 03 Jun 2007 00:07:36 +0200, in comp.lang.c , Richard
<rgr...@gmail.comwrote:
I find it hilarious that you feel the need to tell Richard Heathfield
that. (hint, he knows full well what happens)
Why? The poster, while wrong, doesn't know who or what Richard
Heathfield is.
True, but if they had followed usenet etiquette and lurked,
It depends. The original poster apparently cross-posted
(although his question has nothing to do with clc). You can
lurk for a long time in clc++, and not know who Richard
Heathfield is. (Another reason why cross-posting is bad.)

--
James Kanze (Gabi Software) email: ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jun 3 '07 #49
On 2007-06-03 13:33:20 -0700, "Malcolm McLean" <re*******@btinternet.comsaid:
>
"Army1987" <pl********@for.itwrote in message
news:f3**********@tdi.cu.mi.it...
>>
"Lame Duck" <no****@nospam.comha scritto nel messaggio
news:sl*******************@nospam.com...
>>No, a pointer to a float is the same as an array of float.

#include <stdio.h>
int main(void)
{
float array[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
float *pointer = array;

printf("%lu %lu\n", sizeof array, sizeof pointer);
return 0;
}

Displays "40 4" on my system. So? They're the same but one is ten times
bigger? :-)
So there's a bug in the standard that breaks array pointer equivalence?
It's not a bug, it's that way by design. Pointers and arrays have never
been equivalent.
It happens to even the best languages.
Deprectate sizeof( object) and only allow sizeof(type) and the pro
Not only would that break perfectly valid code, it wouldn't change
anything; arrays would still not be pointers:

#include <stdio.h>
int main(void)
{
printf("%lu %lu\n", (unsigned long)sizeof(float[10]), (unsigned
long)sizeof(float*));
return 0;
}

[OT in clc]
And, in C++, since you can take references to arrays, the situations in
which they are not equivalent to pointers are even greater in number.
[/OT]
--
Clark S. Cox III
cl*******@gmail.com

Jun 3 '07 #50

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

Similar topics

4
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...
4
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
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...
1
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...
36
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...
2
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
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...
2
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...
0
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'...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.