Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: is there anything unstandard in the c part here

Reply
Thread Tools

Re: is there anything unstandard in the c part here

 
 
Uno
Guest
Posts: n/a
 
      07-30-2011
On 07/27/2011 09:24 AM, Keith Thompson wrote:
> James Kuyper<> writes:
> [...]
>> The whole point of using void* rather than char* (when it's appropriate
>> to do so) is the implicit conversions to and from other pointer types.

> [...]
>
> It's not the *whole* point. Another point (I'd argue a more
> important one) is that any pointer value (other than a function
> pointer) can be converted to void* and back again without loss
> of information. That would be quite useful even if conversions to
> and from void* had to be explicit.
>


Keith, am I hallucinating that you told me that all the C standard said
of fortran was that it was a common extension?

As I recall there were two different paragraphs where fortan was mentioned.

All I see now is a reference to the fortran keyword. 3 times in the
same paragraph.

If fortran isn't a common extension, what is?
--
Uno
 
Reply With Quote
 
 
 
 
James Kuyper
Guest
Posts: n/a
 
      07-31-2011
On 07/31/2011 04:19 AM, Gareth Owen wrote:
> Angel <angel+> writes:
>
>> Of course, had you written
>>
>> pa = malloc(50 * sizeof *pa);

>
> Gosh, if only I'd known that, I could have explicitly mentioned it in my
> original post, and you wouldn't have felt it necessary to "correct" me.


My news server lists 3 prior messages of yours on this thread. Neither
the first one, nor the one Angel was responding to, mention that idiom.
The only one that does mentions it, does so only briefly and
dismissively. I think Angel can be forgiven for not having noticed that
you were aware of that idiom, particularly since your arguments seem to
be those of someone who doesn't fully understand the advantages of that
idiom.
--
James Kuyper
 
Reply With Quote
 
 
 
 
arnuld
Guest
Posts: n/a
 
      08-02-2011
> On Tue, 26 Jul 2011 18:42:11 +0000, Seebs wrote:

> ..SNIP...


> Compile C code in C. Don't compile C code in other languages. If you
> need to mix C and other languages, do it by separating C and other
> languages into separate hunks of code. Compile C with the C compiler,
> which does not need casts for malloc. If you need to call C from
> another language, do so by using whatever tools that language has for
> calling C.


I have seen industrial programmers doing casts and saying that it will
need to be compiled by C++ compiler. Many times I have seen this casting
being done in projects where both C and C++ code is being used. Is this a
wrong practice to cast when code has to be compiled by C++ compiler. And
I don't see how can you call C from C++ (may be I am less experienced) ?





--
-- arnuld
www.LispMachine.Wordpress.com
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      08-02-2011
On 08/ 2/11 05:24 PM, arnuld wrote:
>> On Tue, 26 Jul 2011 18:42:11 +0000, Seebs wrote:

>
>> ..SNIP...

>
>> Compile C code in C. Don't compile C code in other languages. If you
>> need to mix C and other languages, do it by separating C and other
>> languages into separate hunks of code. Compile C with the C compiler,
>> which does not need casts for malloc. If you need to call C from
>> another language, do so by using whatever tools that language has for
>> calling C.

>
> I have seen industrial programmers doing casts and saying that it will
> need to be compiled by C++ compiler. Many times I have seen this casting
> being done in projects where both C and C++ code is being used. Is this a
> wrong practice to cast when code has to be compiled by C++ compiler. And


You have to cast from void* in C++.

> I don't see how can you call C from C++ (may be I am less experienced) ?


If you couldn't, how could C++ use the C libraries?

--
Ian Collins
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      08-02-2011
Gareth Owen <> writes:
> Nick Keighley <> writes:
>
>> but on balance omitting the cast is the best option.

>
> For you, probably. In which case I heartily encourage you to continue
> with the style that works for you. But it is a balance, and in such
> issues of *style* people can hold the other view. Which was, after all,
> my original point.
>
>> I don't see how leaving out the cast can hide bugs.

>
> It can.


Perhaps in very rare circumstances, far rarer than the circumstances in
which adding the cast can hide bugs.

--
Keith Thompson (The_Other_Keith) kst- <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      08-02-2011
arnuld <> writes:
>> On Tue, 26 Jul 2011 18:42:11 +0000, Seebs wrote:
>> ..SNIP...

>
>> Compile C code in C. Don't compile C code in other languages. If you
>> need to mix C and other languages, do it by separating C and other
>> languages into separate hunks of code. Compile C with the C compiler,
>> which does not need casts for malloc. If you need to call C from
>> another language, do so by using whatever tools that language has for
>> calling C.

>
> I have seen industrial programmers doing casts and saying that it will
> need to be compiled by C++ compiler. Many times I have seen this casting
> being done in projects where both C and C++ code is being used. Is this a
> wrong practice to cast when code has to be compiled by C++ compiler. And
> I don't see how can you call C from C++ (may be I am less experienced) ?


See section 32 of the "C++ FAQ Lite",
<http://www.parashift.com/c++-faq-lite/>.

There are circumstances where it makes sense to compile the same code as
C or as C++, but in most cases it's better to write C *or* C++, and take
advantage of C++'s interoperability features.

--
Keith Thompson (The_Other_Keith) kst- <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      08-02-2011
On 08/02/2011 01:56 AM, Gareth Owen wrote:
> James Kuyper <> writes:
>
>> I think Angel can be forgiven for not having noticed that you were
>> aware of that idiom, particularly since your arguments seem to be
>> those of someone who doesn't fully understand the advantages of that
>> idiom.

....
> "If you don't agree with me, you don't understand" is not a syllogism.


True. But I wasn't attempting syllogism, nor was I using that argument.
The reasoning I was using could be more accurately summarized as "You
say things which seem to me to be inconsistent with having correctly
understood this" => "You probably don't understand this". The words
"seem" and "probably" indicate the inherent uncertainty that is present
in all discussions in the real world. Syllogism requires at least a
pretense of certainty which can never be justifiable when discussing
real world issues.

Of course, my judgment of what is "correct" is based upon my own
understanding of the topic; but I have no choice about that - I'm stuck
in my own head, I can't use anyone else's understanding for evaluating
the correctness of your statements, I can only use my own. If I'd
thought, as you apparently do, that this is just a subjective issue of
style, rather than an objective issue of functionality, I would not have
even bothered mentioning it. If I had had any serious doubts about the
accuracy of my understanding of this issue, I'd be correspondingly less
judgmental of your misunderstanding. I appreciate that you think I
should have such doubts, but you've presented no arguments sufficiently
convincing to give me any.
--
James Kuyper
 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      08-02-2011
On 08/02/2011 01:24 AM, arnuld wrote:
>> On Tue, 26 Jul 2011 18:42:11 +0000, Seebs wrote:

>
>> ..SNIP...

>
>> Compile C code in C. Don't compile C code in other languages. If you
>> need to mix C and other languages, do it by separating C and other
>> languages into separate hunks of code. Compile C with the C compiler,
>> which does not need casts for malloc. If you need to call C from
>> another language, do so by using whatever tools that language has for
>> calling C.

>
> I have seen industrial programmers doing casts and saying that it will
> need to be compiled by C++ compiler. Many times I have seen this casting
> being done in projects where both C and C++ code is being used. Is this a
> wrong practice to cast when code has to be compiled by C++ compiler. ...


If code needs to be compiled both as C and as C++, such casts are legal
in C and necessary in C++. But the need for such cross-compilable code
is often far less justified than it's proponents imagine.

> ... And
> I don't see how can you call C from C++ (may be I am less experienced) ?


Calling a C routine from C++ requires only that the C++ code contain an
'extern "C"' declaration of the C function. It's the opposite direction
that's a little tricky. You cannot call arbitrary C++ functions from C.
The only C++ functions that can be called from C are those which were
declared 'extern "C"' in their C++ definitions. The 'extern "C"' must
NOT be present in the declaration of the function that is used by the C
code.

--
James Kuyper
 
Reply With Quote
 
Seebs
Guest
Posts: n/a
 
      08-02-2011
On 2011-08-02, arnuld <> wrote:
>> On Tue, 26 Jul 2011 18:42:11 +0000, Seebs wrote:
>> Compile C code in C. Don't compile C code in other languages. If you
>> need to mix C and other languages, do it by separating C and other
>> languages into separate hunks of code. Compile C with the C compiler,
>> which does not need casts for malloc. If you need to call C from
>> another language, do so by using whatever tools that language has for
>> calling C.


> I have seen industrial programmers doing casts and saying that it will
> need to be compiled by C++ compiler. Many times I have seen this casting
> being done in projects where both C and C++ code is being used.


I have seen that too.

> Is this a
> wrong practice to cast when code has to be compiled by C++ compiler.


No. The wrong practice is to set things up so that C code has to be
compiled by a C++ compiler.

> And
> I don't see how can you call C from C++ (may be I am less experienced) ?


Usually, it's very simple: Declare something as extern "C", and then
compile it as C in a separate module, and then... just call it. This
was intentionally made easy, which is why I think that code which "has to
be compiled as C++ too" is almost always a mistaken concept.

-s
--
Copyright 2011, all wrongs reversed. Peter Seebach / usenet-
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
 
Reply With Quote
 
Michael Press
Guest
Posts: n/a
 
      08-03-2011
In article <>,
Joe Pfeiffer <> wrote:

> Angel <angel+> writes:
> >
> > The type of pa being wrong for whatever purpose is a whole different
> > issue that is outside of scope of what is being discussed, and does not
> > invalidate the statement in any way. By that logic, you'd need casts
> > for every assigment you do, not just memory allocations.

>
> No, you assume the compiler will tell you about type conflicts when it
> can. This is just an argument for casting void*'s -- something I've
> never done in the past, but this discussion has just about convinced me
> to start doing it.
>
> > Besides, if you don't know the type and purpose of your own variables,
> > you have a problem anyway, no matter how many casts you put in.

>
> I think it's a pretty safe statement about bugs in general that somehow,
> somewhere, someway, you don't know what your code is doing. A very
> common part of discussions with students asking me for help with their
> code went:
>
> me: "so let's put a printf here...."
> student: "but that's just $assumption there"
> me: "if we knew what your code was doing, you wouldn't be in my
> office"



--My program was working perfectly yesterday, and now it crashes.
--What did you change?
--Nothing!

Took a while to find the answer to this.

--Then why did you rerun it?

--
Michael Press
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: is there anything unstandard in the c part here Nick Keighley C Programming 16 08-01-2011 03:20 PM
Re: is there anything unstandard in the c part here Barry Schwarz C Programming 11 07-27-2011 06:10 PM
Does anyone Here know anything about when Digtial phones will bereleased David S. Computer Support 13 08-12-2005 03:28 AM
ActiveX apologetic Larry Seltzer... "Sun paid for malicious ActiveX code, and Firefox is bad, bad bad baad. please use ActiveX, it's secure and nice!" (ok, the last part is irony on my part) fernando.cassia@gmail.com Java 0 04-16-2005 10:05 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57