473,382 Members | 1,442 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,382 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
156 5680
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 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'...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.