469,360 Members | 1,686 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,360 developers. It's quick & easy.

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
156 4682
Keith Thompson wrote, On 09/06/07 20:39:
"Malcolm McLean" <re*******@btinternet.comwrites:
[...]
>One problem is that when we take this example

int x;
int *ptr = &x;

it is quite hard to explain the advantage of the operation.

I'm not convinced that the student has to understand why each concept
is useful at the time that it's presented. The "hello, world" program
isn't particularly useful by itself; I think most students can
understand that it's leading to something else.
However, using pointers as parameters to functions is very useful, so if
you want to introduce pointers (but not all they can do) before arrays
it is easily possible. I would not, but it can be done.
>Pointers don't actually make much sense until you've got a reasonable
amount of code.
You can make sensible use of them in 100 lines or less.
>Then the increment rule is so fundamental that really
you must introduce pointers to arrays very quickly.

I assume you're referring to the fact that an array can be accessed
via a pointer to its first element. Actual pointers to arrays are
rarely useful.
Agreed.
>So it should be arrays, then function calls, and then pointers and how
to pass arrays to functions. sizeof() doesn't make much sense outside
of a pointer context.

sizeof makes perfect sense; it yields the size in bytes of its
argument. The *usefulness* of sizeof isn't quite as obvious.
Agreed.
> Introduce when you come to malloc(), which has
to be after pointers to arrays are mastered.

Pointers to structures can be used to build linked lists and other
dynamic data structures. (I'm not sure that such things should be
introduced before arrays, though.)
I strongly agree with this. An array is a far simpler data structure and
so should be introduced first. They can be taught without ever having to
mention the relationship to pointers, although for some usage you have
to start getting close.
--
Flash Gordon
Jun 10 '07 #151
CBFalconer <cb********@yahoo.comwrites:
Keith Thompson wrote:
>peter koch <pe***************@gmail.comwrites:
>>CBFalconer <cbfalco...@yahoo.comwrote:
pete wrote:
... snip ...
>>>>
I don't know much about pedagogy,
but I think that before that, I would teach that
sizeof((char)0 + (char)0 + (char)0) equals sizeof(int).

I believe you are wrong here, in that the number of terms in the
expression doesn't matter, provided there is at least one term.

I believe that the poster wanted to tell about the difference
between C and C++ wrt. sizeof('a').

I believe both of you missed the point.

I didn't. Read what I wrote again.
Ok.

....

The second part of your statement is correct (the number of terms in
the expression doesn't matter, provided there is at least one term),
but I don't see how it implies that pete was wrong.

--
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 10 '07 #152
Keith Thompson wrote:
CBFalconer <cb********@yahoo.comwrites:
>Keith Thompson wrote:
>>peter koch <pe***************@gmail.comwrites:
CBFalconer <cbfalco...@yahoo.comwrote:
.... snip ...
>>>>>
I believe you are wrong here, in that the number of terms in the
expression doesn't matter, provided there is at least one term.

I believe that the poster wanted to tell about the difference
between C and C++ wrt. sizeof('a').

I believe both of you missed the point.

I didn't. Read what I wrote again.

Ok.

...

The second part of your statement is correct (the number of terms in
the expression doesn't matter, provided there is at least one term),
but I don't see how it implies that pete was wrong.
But that was ALL that I said. Note the "in that" phrase.

--
<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 10 '07 #153
CBFalconer <cb********@yahoo.comwrites:
Keith Thompson wrote:
>CBFalconer <cb********@yahoo.comwrites:
>>Keith Thompson wrote:
peter koch <pe***************@gmail.comwrites:
CBFalconer <cbfalco...@yahoo.comwrote:
>
... snip ...
>>>>>>
>I believe you are wrong here, in that the number of terms in the
>expression doesn't matter, provided there is at least one term.
>
I believe that the poster wanted to tell about the difference
between C and C++ wrt. sizeof('a').

I believe both of you missed the point.

I didn't. Read what I wrote again.

Ok.

...

The second part of your statement is correct (the number of terms in
the expression doesn't matter, provided there is at least one term),
but I don't see how it implies that pete was wrong.

But that was ALL that I said. Note the "in that" phrase.
Where did pete claim that the number of terms did matter?

--
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 10 '07 #154

"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
"Malcolm McLean" <re*******@btinternet.comwrites:
[...]
>One problem is that when we take this example

int x;
int *ptr = &x;

it is quite hard to explain the advantage of the operation.

I'm not convinced that the student has to understand why each concept
is useful at the time that it's presented. The "hello, world" program
isn't particularly useful by itself; I think most students can
understand that it's leading to something else.
He does have to understand why what he is beign taught is useful. To some
extent you must trust the instructor. However it helps.

"Hello World", for instance, produces something on the screen.
In assembly, the equivalent is "return x", because there is no easy way of
calling an IO routine from assembly language. So we could say that the
simplest C program that actually does something is one that just returns a
flag to the environment. However that doesn't have the satisfying feel of
"I've made the computer do something" to it.
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Jun 10 '07 #155
Malcolm McLean wrote:
>
.... snip ...
>
"Hello World", for instance, produces something on the screen.
In assembly, the equivalent is "return x", because there is no
easy way of calling an IO routine from assembly language. So we
could say that the simplest C program that actually does
something is one that just returns a flag to the environment.
However that doesn't have the satisfying feel of "I've made the
computer do something" to it.
Not so. Provided an i/o port exists, you can either write a
routine that does it, and call that, or write something like:

putch: push a
push c
mov a, ch
mvi c, putc
call sys
pop c
pop a
ret

Take a look at the modules involved in stdio.h for examples.

--
<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 10 '07 #156
On Sun, 10 Jun 2007 10:00:41 -0400, CBFalconer wrote:
>putch: push a
push c
mov a, ch
mvi c, putc
call sys
pop c
pop a
ret
are you more a C programmer or an assembly programmer?
Jun 14 '07 #157

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Joseph Suprenant | last post: by
4 posts views Thread by Eric | last post: by
2 posts views Thread by Richard L Rosenheim | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.