read image from url

R

Richard Heathfield

Phlip said:
Richard Heathfield wrote:



And when they change their name to "Troll4", just to say "hah hah - you
can't resist me!", then it might just be less constructive...

That doesn't appear to be relevant in this case, however.
 
M

Mark McIntyre

I would conjecture that it was because Martin Ambuhl and you ignored the
clause "if you take out C++ extensions".

I guess I ignored it because it was as idiotic as the rest of the
remark.

Fortran is pretty much like French, if you take out the Fortran
extensions.
could you elaborate on this one
main.


Isn't that a C++ extension?

It can't be an extension to C++ since its part of the C++ standard.
The stream IO, I would consider an extension. What are the huge (not minor)
differences between C and C++ with regard to the printf family?

Whats the effect of << in C?
new/delete is an extension. What are the big differences in malloc/free
between C and C++?

This is a C FAQ.

BTW I forgot to mention operator overload.
--
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
 
P

Philipp

jacob said:
Why be pedantic man?

It is OBVIOUS TO MOST PEOPLE (besides the pedantic ones) what the
original poster wanted.

Just a newbie question: If you are writing a C++ programm and need some
function to do some stuff (as the OP), is it ok to use a C function
which you found somewhere on the web in your code?

Or is there such a thing as a "rule" which stipulates that you would
_have_ to rewrite the code using C++ ideas?
(sounds pretty stupid to me if you are applying the rules of the FAQ
saying that main factors are time, money and risk
(http://www.parashift.com/c++-faq-lite/big-picture.html#faq-6.17)

Phil
 
I

Ian Collins

Philipp said:
Just a newbie question: If you are writing a C++ programm and need some
function to do some stuff (as the OP), is it ok to use a C function
which you found somewhere on the web in your code?
Yes. The only issues are going the other way.
 
P

Philipp

Ian said:
Yes. The only issues are going the other way.

So what's so wrong from the OP about asking for a piece of code in
(either) C or C++ to do some stuff?

(He's not implying that C or C++ are the same (or even similar). He's
just saying, "both will work for me").

PS: Or is the real problem that one should write "C or C++" instead of
"C/C++" ? (come on...)
 
J

jacob navia

Philipp said:
So what's so wrong from the OP about asking for a piece of code in
(either) C or C++ to do some stuff?

(He's not implying that C or C++ are the same (or even similar). He's
just saying, "both will work for me").

PS: Or is the real problem that one should write "C or C++" instead of
"C/C++" ? (come on...)

Well, that is precisely what I meant when I said that there were "minor"
differences. You can use any C function in C++ by qualifying it as
extern "C", and that is it, you can use it as you want!

All the insults, flames, etc can't hide this simple fact.
 
F

Frederick Gotham

jacob navia posted:
You can use any C function in C++ by qualifying it as extern "C", and
that is it, you can use it as you want!

Must every C++ compiler provide a facility for compiling C code? Can the
following program be considered universally portable?

/* stuff.c */

#include <stddef.h>
#include <stdlib.h>

char *AllocCharArray( size_t const len )
{
return malloc(len);
}


/* main.cpp */

#include <cstdlib>

extern "C" { char *AllocCharArray( std::size_t const len ); }

int main()
{
char * const p = AllocCharArray(64);

std::free(p);
}
 
T

TB

jacob navia skrev:
Well, that is precisely what I meant when I said that there were "minor"
differences. You can use any C function in C++ by qualifying it as
extern "C", and that is it, you can use it as you want!

All the insults, flames, etc can't hide this simple fact.

extern "C" {
void foo(int * restrict, int * restrict) {}
void bar(int n, int a[static 5][n + 1]) {
int v[a[4][n]];
}
}
 
M

Mark McIntyre

So what's so wrong from the OP about asking for a piece of code in
(either) C or C++ to do some stuff?

If he'd done that, there'd be no problems though the C solution might
have been inappropriate or inefficient or potentially just plain
incorrect in C++. F'rinstance a C solution wouldn't cast the return
from malloc, and might use sizeof('a'). It might be more eficient to
use a container of some sort.

What he instead asked for was a solution in the mythical language
C/C++.

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

Mark McIntyre

You can use any C function in C++ by qualifying it as
extern "C", and that is it, you can use it as you want!

This is completely wrong.
All the insults, flames, etc can't hide this simple fact.

Perhaps once you've actually tried this properly, you'll be able to
post a correction.



--
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
 
A

Al Balmer

Sorry if I'm confused.
in FAQ http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html#faq-32.5
it says that "you can declare the individual C function in your C++ code
using the extern "C" syntax"

Is this wrong? (!)

"Declare" is not the same as "use." The "extern C" wrapper just
disables name mangling, so that the function is called with it's
proper name. It doesn't magically make non-C code C++ compatible.

Normally, the way this is used is that you have a C function (perhaps
in a library) which has been compiled by a C compiler. You want to
call this function from a C++ program. If you declare it in the normal
way, the compiler will transform ("mangle") the name by adding
information about the parameter types, for example. The name generated
won't match the name of the C function, and the linker won't be able
to find it. If you declare the function using "extern C", the C++
compiler will leave the name as is.
 
K

Kai-Uwe Bux

Mark said:
If he'd done that, there'd be no problems though the C solution might
have been inappropriate or inefficient or potentially just plain
incorrect in C++. F'rinstance a C solution wouldn't cast the return
from malloc, and might use sizeof('a'). It might be more eficient to
use a container of some sort.

What he instead asked for was a solution in the mythical language
C/C++.

We just face some possibilities:

a) the OP asked a non-senscal question.

b) some other posters offered a non-sensical interpretation of the original
question because they take offense in the string "C/C++" for whatever
reasons.

In interpretation, as in translation, there is a prima-facie principle: if
an interpretation (or translation) renders a phrase patently wrong or
meaningless or non-sensical, chances are that the interpretation is
mistaken. The goal of interpreting some statement or question should be
understanding not ridicule.


Best

Kai-Uwe Bux
 
K

Kai-Uwe Bux

Mark said:
I guess I ignored it because it was as idiotic as the rest of the
remark.

Fortran is pretty much like French, if you take out the Fortran
extensions.


It can't be an extension to C++ since its part of the C++ standard.


Whats the effect of << in C?


This is a C FAQ.

BTW I forgot to mention operator overload.

Your response shows that your understanding of the term "C++ extension"
seems to be: a language feature offered by some implementation of C++ in
addition to the C++ language as defined per the C++ standard. Although that
is in some contexts a perfectly legitimate interpretation of the
phrase "C++ extension", you should reconsider this reading for the context
of jacob's post. I have provided an alternative interpretation elsethread
that makes more sense. I think, jacob used the phrase "if you take out C++
extensions" to mean: "if you disregard those language features of C++ that
it has in addition to those inherited from C".


Best

Kai-Uwe Bux
 
?

=?ISO-8859-15?Q?Juli=E1n?= Albo

Philipp said:
Just a newbie question: If you are writing a C++ programm and need some
function to do some stuff (as the OP), is it ok to use a C function
which you found somewhere on the web in your code?

That depends of the meaning of "use". You can compile it with a C compiler,
write a header with the declaration of the function as extern "C" and link
with your C++ code, if you have both compilers available and binary
compatibles. In that case, asking about the function in a C++ group is
nonsense.

Or you can copy the function in a C++ program and compile it as C++. But for
a newbie it can be difficult to verify that the code has the same meaning
in both languages, or to interpret any errors or warnings that may appear
when compiling it as C++. And as a newbie the time will be better used in
learning more C++ that in exploring the differences between C and C++.
 
G

Gavin Deane

Kai-Uwe Bux said:
We just face some possibilities:

a) the OP asked a non-senscal question.

There are two very different variants of that

a1) the OP intentionally asked a question they knew to be non-sensical
a2) the OP asked what is actually a non-sensical question but believed
they were asking a meaningful question

Unless the OP was deliberately trolling, a1 is not the case. However,
given the number of people here (and in the real world) who use the
phrase "C/C++" and later reveal a mistaken belief that the distinction
between C and C++ is irrelevant to their question, or even a failure to
understand that the two are sufficiently different that, for all but
the most trivial of questions, the answer in C and the answer in C++
may bear no resemblance to each other, a2 is a definite possibility.
b) some other posters offered a non-sensical interpretation of the original
question because they take offense in the string "C/C++" for whatever
reasons.

I've seen "C/C++" used to mean at least three different things and
rarely is it clear from the context which is meant:

1) I need one solution that will work in both C and C++.
2) I need either a solution in C or a solution in C++. I understand the
distinction and I expect that the C solution would differ from the C++
solution and that the C solution might not work in C++.
3) I need one solution in the language I'm using and I had no idea that
C and C++ were distinct, either formally or idiomatically.

3 is not uncommon and that lack of understanding produces the sort of
hotch-potch of C and C++ code that gets posted here all the time.
Having to work with code like that is frustrating and is probably the
cause of some people's (mine included) irritation at the use of the
term "C/C++".
In interpretation, as in translation, there is a prima-facie principle: if
an interpretation (or translation) renders a phrase patently wrong or
meaningless or non-sensical, chances are that the interpretation is
mistaken. The goal of interpreting some statement or question should be
understanding not ridicule.

The possibility here is that interpretation that rendered the question
patently wrong could well have been exactly the right interpretation
because of a lack of understanding on the questioner's part.

Notwithstanding the irritation caused, it is undoubtedly more
constructive to educate away the misunderstanding (if misunderstanding
is the reason "C/C++" was used) than to ridicule.

Given that the use of "C/C++" to mean the non-sensical and mythical
combination of the two is not uncommon, I would advise anyone who does
understand the similarities and differences to be explicit to avoid
appearing uneducated. Make it clear whether you mean "an answer in C or
an answer in C++ is sufficient" or "I need an answer that will work in
both C and C++".

Gavin Deane
 
J

jacob navia

Al said:
"Declare" is not the same as "use." The "extern C" wrapper just
disables name mangling, so that the function is called with it's
proper name. It doesn't magically make non-C code C++ compatible.

Normally, the way this is used is that you have a C function (perhaps
in a library) which has been compiled by a C compiler. You want to
call this function from a C++ program. If you declare it in the normal
way, the compiler will transform ("mangle") the name by adding
information about the parameter types, for example. The name generated
won't match the name of the C function, and the linker won't be able
to find it. If you declare the function using "extern C", the C++
compiler will leave the name as is.

And this means that both languages are binary compatible, hence very
close, as I am arguing since quite a few posts.

This is a FAQ, and the answer is in the C++ FAQ. I am not proposing
something so stupid that I can be treated "an idiot", (by Mr Ambuhl)
or "mentally retarded" (by Mr Gotham) or whatever!!!

Today good manners are considered a thing from the past. Violence
and provocation are the best way to impose your opinions. It is no
longer important to convince other participants in the discussion but
to be crowned as the "alpha male" of the group and build a circle
of religious followers.

People that do not feel this urgent need to make a sect, are "free
game" and can be insulted at will.
 
A

Al Balmer

And this means that both languages are binary compatible, hence very
close, as I am arguing since quite a few posts.

Well, sort of, but I don't want to get into this. I think, especially
considering the remainder of your post, that you must have meant to
reply to some other message.
 
A

Andrew Poelstra

And this means that both languages are binary compatible, hence very
close, as I am arguing since quite a few posts.

I have a great free book called "PC Assembly Language" which explains
how to set up your assembly functions so that they'll link with C. By
your definition, C and x86 Assembler are binary compatible.

Does that make them very close languages?
 
R

Richard Heathfield

jacob navia said:

Today good manners are considered a thing from the past.

Not entirely. There are still /some/ people who observe topicality, who
refrain from making incorrect "corrections" or at least have the grace to
apologise when they do so, who don't habitually plug their principal
product, and so on and so on.
Violence and provocation are the best way to impose your opinions.

They cut little ice on Usenet, and anyway, to "impose" your opinions is
never a good idea. Persuasion is much more effective, and you won't
persuade people without being able to present a reasoned case.
It is no
longer important to convince other participants in the discussion

It never was. Convincing people is utterly unimportant. The goal is truth,
not conviction, and in clc (and presumably in clc++) we arrive at truth by
having reasoned discussion with due reference to the Standard.

<nonsense snipped>
 

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,770
Messages
2,569,586
Members
45,097
Latest member
RayE496148

Latest Threads

Top