Converting to/from pointer

M

Mark McIntyre

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
 
R

Richard

Mark McIntyre said:
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.
 
F

Flash Gordon

Richard wrote, On 02/06/07 23:21:
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.
 
R

Richard

Flash Gordon said:
Richard wrote, On 02/06/07 23:21:

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.
 
C

Clark Cox

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.
 
M

Martin Ambuhl

Ian said:
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.
 
I

Ian Collins

Martin said:
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?
 
K

Keith Thompson

Martin Ambuhl said:
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.)
 
L

Lame Duck

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!
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.
 
L

Lame Duck

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".
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.
 
R

Richard Heathfield

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.
 
R

Richard Heathfield

Lame Duck said:
On 2 Jun 2007 at 21:42, Ben Pfaff 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".

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.

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.
 
I

Ian Collins

Lame said:
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.
 
M

Malcolm McLean

Lame Duck said:
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.
 
M

Malcolm McLean

Lame Duck said:
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.
 
R

Richard

Lame Duck said:
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.
 
A

Army1987

Lame Duck said:
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? :)
 
A

Army1987

Martin Ambuhl said:
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.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,241
Latest member
Lisa1997

Latest Threads

Top