POV-Ray : Newsgroups : povray.off-topic : Teach yourself C++ in 21 days Server Time
30 Jul 2024 10:15:51 EDT (-0400)
  Teach yourself C++ in 21 days (Message 141 to 150 of 168)  
<<< Previous 10 Messages Goto Latest 10 Messages Next 10 Messages >>>
From: Invisible
Subject: Re: Day 6
Date: 24 Apr 2012 04:11:57
Message: <4f96604d@news.povray.org>
On 20/04/2012 02:03 PM, Invisible wrote:
> On 20/04/2012 01:36 PM, Warp wrote:
>> Orchid Win7 v1<voi### [at] devnull> wrote:
>>> On the other hand, it appears to be aimed at people who already know the
>>> C++ language. That isn't really me, yet. I know some of the syntax, but
>>> certainly not all of it, or what all of it actually does.
>>
>> I think you'll learn on the fly (at least if you have the right
>> attitude).
>
> Given that I already some some clue about C++, that might actually work...

You know what? I'm just going to /buy/ the book. In the unlikely event 
that it actually helps me to get a better job, it will have easily paid 
for itself multiple times over.


Post a reply to this message

From: Darren New
Subject: Re: Days 1-5
Date: 25 Apr 2012 01:16:09
Message: <4f978899$1@news.povray.org>
On 4/23/2012 1:08, Invisible wrote:
> a valid operator that you can put anywhere you want...

It has to be between two other arguments, and you can't write a naked comma 
operator in the middle of a function's arguments, because commas separate 
function arguments. So you'd still get a compiler error.

-- 
Darren New, San Diego CA, USA (PST)
   "Oh no! We're out of code juice!"
   "Don't panic. There's beans and filters
    in the cabinet."


Post a reply to this message

From: Darren New
Subject: Re: Days 5-
Date: 25 Apr 2012 01:17:19
Message: <4f9788df@news.povray.org>
On 4/24/2012 0:07, Le_Forgeron wrote:
> The mangling pattern/scheme of C++ for function's name

Ah yes.  I had forgotten about that.

-
Darren New, San Diego CA, USA (PST)
   "Oh no! We're out of code juice!"
   "Don't panic. There's beans and filters
    in the cabinet."


Post a reply to this message

From: Darren New
Subject: Re: Days 5-
Date: 25 Apr 2012 01:22:54
Message: <4f978a2e@news.povray.org>
On 4/23/2012 1:31, Invisible wrote:
> Damn... I'm trying to think of something you can code without actually using
> recursion. Hmm. Well, I guess there must be /something/...

Almost all business logic. I don't remember seeing any recursion in any 
operating system kernels I've read. I can't think of any recursive SQL code 
I've written at all.

> So if you want to count how many nodes there are in a binary tree, how do
> you do that non-recursively?

You use a queue. Each node you visit, you tack on to the end of the queue to 
be counted, and you go until the queue is empty.

Alternately, manually maintain the stack. Which is not "recursion" in the C 
sense, because you can actually tell without just blasting memory in unknown 
ways when you run out of room for the stack.

> If a programming language supports calling /any/ foreign language, that
> language will always be C. It will know about standard C types, it will
> usually know about C structs, and it will let you call arbitrary C functions.

OK. Yes, as long as you link to the proper C calling convention.

> And yet, the way that you call a C function is, apparently, undefined.

It's implementation-defined. You have to read the compiler manual (or source 
code) to know what the sequence is. And different functions in the same code 
can have different calling conventions.

Unless you have a CPU that actually enforces calling conventions.

> It also makes me wonder how the heck it's possible to take object code from
> multiple C compilers and link it all together, if each of them is
> potentially using a completely different calling convention. It sounds like
> it shouldn't work.

And indeed it doesn't. Try compiling one library with gcc and another with 
visual C and see if they link cleanly. Take a library off the mac and link 
it to a Windows-compiled main().

For that matter, try compiling one program for x86 and the other for x64.

-- 
Darren New, San Diego CA, USA (PST)
   "Oh no! We're out of code juice!"
   "Don't panic. There's beans and filters
    in the cabinet."


Post a reply to this message

From: Darren New
Subject: Re: Teach yourself C++ in 21 strange malfunctions
Date: 25 Apr 2012 01:23:47
Message: <4f978a63$1@news.povray.org>
On 4/23/2012 0:59, Invisible wrote:
>>> I think it's probably vacuous to try to estimate how "useful" it would be
>>> without actually trying it...
>>
>> Well, they tried making STM work on .NET and gave up because of all the
>> state, if you remember.
>
> They gave up because they tried to make all the existing state mutation
> stuff still work in the presence of transactions, which is /obviously/
> impossible.

That's my point.  How useful would it be if you couldn't actually use any of 
the other .NET libraries, including even I/O, reflection, etc.?

-- 
Darren New, San Diego CA, USA (PST)
   "Oh no! We're out of code juice!"
   "Don't panic. There's beans and filters
    in the cabinet."


Post a reply to this message

From: Invisible
Subject: Re: Teach yourself C++ in 21 strange malfunctions
Date: 25 Apr 2012 04:12:35
Message: <4f97b1f3$1@news.povray.org>
>>> Well, they tried making STM work on .NET and gave up because of all the
>>> state, if you remember.
>>
>> They gave up because they tried to make all the existing state mutation
>> stuff still work in the presence of transactions, which is /obviously/
>> impossible.
>
> That's my point. How useful would it be if you couldn't actually use any
> of the other .NET libraries, including even I/O, reflection, etc.?

You do all of that stuff from /outside/ your transactions, that's all. 
Remember, transactions are only for thread communication. You start a 
transaction, fetch the next work item from the shared work queue, and 
the transaction. Then you process the work item, calling whatever 
libraries you need. Simples.


Post a reply to this message

From: Invisible
Subject: Re: Days 5-
Date: 25 Apr 2012 04:22:26
Message: <4f97b442$1@news.povray.org>
On 25/04/2012 06:22 AM, Darren New wrote:
> On 4/23/2012 1:31, Invisible wrote:
>> Damn... I'm trying to think of something you can code without actually
>> using recursion. Hmm. Well, I guess there must be /something/...
>
> Almost all business logic.

I suppose I should consider myself lucky that I'm never going to be 
writing anything like that.

> I don't remember seeing any recursion in any
> operating system kernels I've read.

Really? That's surprising. No recursive sorting algorithms for balancing 
the B*-trees that the directory nodes use, or for sorting the ready 
thread list by priority?

> I can't think of any recursive SQL code I've written at all.

SQL is a rather special-purpose language. I'm not sure it even 
/supports/ recursion...

>> So if you want to count how many nodes there are in a binary tree, how do
>> you do that non-recursively?
>
> You use a queue. Each node you visit, you tack on to the end of the
> queue to be counted, and you go until the queue is empty.

In other words, you manually implement the stack.

Tell me, in what way does this prevent you running out of stack?

>> And yet, the way that you call a C function is, apparently, undefined.
>
> It's implementation-defined. You have to read the compiler manual (or
> source code) to know what the sequence is. And different functions in
> the same code can have different calling conventions.
>
> Unless you have a CPU that actually enforces calling conventions.

So... how is it ever possible to statically link software?

>> It sounds like it shouldn't work.
>
> And indeed it doesn't. Try compiling one library with gcc and another
> with visual C and see if they link cleanly.

It's news to me that this /doesn't/ work.

I mean, if every compiler uses its own random calling convention, then 
how /the hell/ is it possible to write some C, link it against GMP, 
wxWidgets and the OS header files, and get a usable binary? You know, 
given that you have no idea which compiler these libraries are compiled 
with...

> Take a library off the mac and link it to a Windows-compiled main().

Yeah, well, one is going to be an ELF object, and the other will be a PE 
module. You won't even be able to find a linker program that understands 
both file formats. :-P That has nothing to do with whether the machine 
code within those files would work if you linked it together.

> For that matter, try compiling one program for x86 and the other for x64.

There's absolutely no reason to expect binaries for different 
architectures to work together.

I would, however, expect that on any given architecture, the C calling 
convention is always the same.


Post a reply to this message

From: Warp
Subject: Re: Day 6
Date: 25 Apr 2012 07:59:59
Message: <4f97e73f@news.povray.org>
Invisible <voi### [at] devnull> wrote:
> You know what? I'm just going to /buy/ the book.

  I'd recommend getting both of them. (Of course you could buy the
"Effective C++" first, and if you like it, buy "More Effective C++"
later.)

-- 
                                                          - Warp


Post a reply to this message

From: Francois Labreque
Subject: Re: Days 5-
Date: 25 Apr 2012 08:25:24
Message: <4f97ed34$1@news.povray.org>
Le 2012-04-25 04:22, Invisible a écrit :
> On 25/04/2012 06:22 AM, Darren New wrote:
>> On 4/23/2012 1:31, Invisible wrote:
>>> Damn... I'm trying to think of something you can code without actually
>>> using recursion. Hmm. Well, I guess there must be /something/...
>>
>> Almost all business logic.
>
> I suppose I should consider myself lucky that I'm never going to be
> writing anything like that.

Why not?  Didn't you rewrite the code to compile your danse tournament 
rankings?  I know you only did it for yourself, but that was business 
logic, even if you weren't using WebSphere, J2EE, Weblogic or some big 
platform like that.

>
>>> And yet, the way that you call a C function is, apparently, undefined.
>>
>> It's implementation-defined. You have to read the compiler manual (or
>> source code) to know what the sequence is. And different functions in
>> the same code can have different calling conventions.
>>
>> Unless you have a CPU that actually enforces calling conventions.
>
> So... how is it ever possible to statically link software?
>

You have to take extra steps to make sure it works.  For example, back 
in the days of Windows 3.1, you had to use the Pascal calling convention 
for your functions in order to make sure that they could interact with 
other modules.  (Maybe it's still that way, I haven't touched a C 
program in 15 years.)

-- 
/*Francois Labreque*/#local a=x+y;#local b=x+a;#local c=a+b;#macro P(F//
/*    flabreque    */L)polygon{5,F,F+z,L+z,L,F pigment{rgb 9}}#end union
/*        @        */{P(0,a)P(a,b)P(b,c)P(2*a,2*b)P(2*b,b+c)P(b+c,<2,3>)
/*   gmail.com     */}camera{orthographic location<6,1.25,-6>look_at a }


Post a reply to this message

From: Invisible
Subject: Re: Day 6
Date: 25 Apr 2012 09:08:24
Message: <4f97f748$1@news.povray.org>
On 25/04/2012 12:59 PM, Warp wrote:
> Invisible<voi### [at] devnull>  wrote:
>> You know what? I'm just going to /buy/ the book.
>
>    I'd recommend getting both of them. (Of course you could buy the
> "Effective C++" first, and if you like it, buy "More Effective C++"
> later.)

I think I can actually buy the pair for a lower price... (Amazon likes 
to do that.)

Gotta love how Amazon screwed me over, and I was all pissed about it, 
and now here I am giving them my money again.


Post a reply to this message

<<< Previous 10 Messages Goto Latest 10 Messages Next 10 Messages >>>

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.