From: Andre Kaufmann on
Dragan Milenkovic wrote:
> Andre Kaufmann wrote:
>
> Doesn't boost::python offer such functionality?

It's used to make C++ code accessible to Python code and vice versa.
And I agree, Python is really good for scripting, although IMHO LUA is
easier to integrate in multi threaded applications.

> [...]
> very easy. It works the both ways.

Yes, but it's not C++ and it's not really compiled to native code.
So to get the same as in C#/.NET you would have to ship a C++ compiler,
which compiles the code and dynamically links to it at runtime.
It's possible, but I wouldn't recommend it, since C++ isn't the
perfect "scripting language" ;-)

> How is security implemented in the mentioned C# feature? I'm guessing
> it wouldn't let just any code compile and/or execute.

It's bound to the same security restrictions as the other code.
The .NET runtime enforces security.


> [...]
> The two are different. With meta programming you can get compile-time
> diagnostics. Can you have this done in any other language?

Yes, in the D language.
But not in C#, C++ has some advantages - I won't deny that ;-).
Anyways there a plenty of static code analysis tools and you can ship
your application with debug code, which normally isn't compiled, but if
a little debug switch is enabled you will have a full debug version of
your application.


> [...]
> Isn't this more ABI related? I don't think C++ itself imposes
> such limitation. Unfortunately, I'm not familiar with ABI-related
> future improvements.

Yes that is the problem, C++ doesn't impose a limitation, but it doesn't
standardize it either.


> [...]
> Hm... Do you ever _really_ _need_ to do this? The only case I can think
> of is when there is only a library for one platform and no way and
> no source to build it for another. But this requires a kind of
> virtual machine or such environment, which is not the goal of C++.
>
> Should such need come, I would just use Java...

Java could have been the same (directly in the beginning), a platform
for multiple languages. And to interact with native code in Java is just
a pain.


> [...]
> Because after quite a few generations of failures they finally got
> it right... Think AWT, MFC... or did they get it right? I don't know...

I think QT got it right. Unfortunately it's not a standard.

> [snip]
>
> [...]
> And why would there be a constructor involved with a static value?
> I don't think that those two cases can be compared.

Where's the difference if I initialize a static or a class member ?

class a { static int v; };
class b { int v; };

To initialize them I have to write:

int a::v = 1;
b::b() : v(1) {}

Why can't I simply write ?:

class a { static int v = 1; };
class b { int v = 1; };

I can simulate that in C++ however by using template classes, then I can
write:

class b { IntAutoInit<1> v; };


> [...]
> Well, maybe we should lobby that C# gets a RAII? In the end,
> it is only one feature compared to many missing ones of C++.
> Anyway, to cut the silly talk... C++ has some shortcomings,
> most of them coming as a legacy, but these presented here are
> more ABI and library/environment (don't know how else to name it)
> related.

This wasn't a discussing about C++ short commings,
only about the statement of M. Gaunard:

In C++ ....
"you can do whatever you want with it".

I only listed some examples, which are more easier in other languages to
solve than in C++.

Andre

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: demo on
On Jul 8, 5:56 am, Andre Kaufmann <akfmn...(a)t-online.de> wrote:
> void foo()
> {
> auto Double = [] (int x) { return x * x; };
> auto Tripple = [] (int x) { return x * x * x; };
> auto DoubleTripple = Compose<int>(Double, Tripple);
> printf("%d\r\n", DoubleTripple(3));
>
> }
>
> How do I get rid of the type [int] ? I could wrap the functions Double
> and Tripple in template functions too, but how do I combine 2 functions
> with Compose, without specifying a type ?
> I tried to get a compilable template function of Compose with a
> combination of "auto" and "decltype" to forward the type, but couldn't
> get it compiled, without specifying the parameter type.

I wondered about if this was possible with Boost.Phoenix, and got an
answer from Thomas Heller.
Using the (unfinished/unreleased) phoenix3, foo could be written as:

void foo()
{
using boost::phoenix::arg_names::arg1;

auto Double = arg1 * arg1;
auto Tripple = arg1 * arg1 * arg1;
auto DoubleTripple = Double(Triple(arg1));
printf("%d\r\n", DoubleTripple(3));
}


--
Eld p� �ren og sol p� eng gjer mannen fegen og fj�g. [J�tul]
<demo> 2010 Tore Halvorsen || +052 0553034554


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Andre Kaufmann on
Edward Rosten wrote:
> On Jul 4, 9:51 pm, Andre Kaufmann <akfmn...(a)t-online.de> wrote:
>
>>> It's an entirely different model.
>> Many languages offer that. E.g. C#.
>
> That would be the .net platform rather than C# per-se. But, not one of
> those languages/platforms has anything like the portability of C++.
> Consider trying to make it work on a microcontroller with executable
> code stored in NOR flash...

Well, there's the .NET Micro Framework for microcontrollers.
But anyways I don't think C++ is commonly used for microcontroller
coder, IMHO that's commonly C code.


Regarding portability, I rather would say, that standard C++ isn't that
portable too. Have a look at boost, how many #idefs there are to ensure
that it compiles under every compiler and platforms.
And even if the C++ code is portable, you have always parts which call
directly into OS functions (e.g. GUI), which must be implemented for
each platform differently.

>
> Again, I think you mean the .net platform, not C# per se. I believe
> the .nettified C++ can also do this.

It's mixed code, which C++/CLI generates - commonly used to generate
..NET wrapper code for C++ code.

> I may be wrong. Also, I'm
> slightly skeptical of the entire concept, given some experience of it.
> Languages tend to be different because their view of the world is

The view of the world is different, the world itself not ;-)
In .NET you can also compile code, which isn't usable in all languages.
But at least there is a common basis, on which all languages agree.


>
>>>> - Can I mix C++ code libraries compiled for different platforms
>>> Can you do this in ANY language?
>> C# for example.
>
> No. You can only mix code compiled for the .net platform. Much like
> you can mix binary code compiled for your platform's ABI (or C++ ABI).

Yes, but the .NET platform runs under multiple native platforms, which
itself is compiled (at runtime) to native code.
C++ could also do this - in many C++ compilers do compile not directly
native code, but intermediate code.

> [...]

Andre

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Dragan Milenkovic on
Walter Bright wrote:
> Ian Collins wrote:
>> On 07/ 8/10 08:16 AM, Walter Bright wrote:
>>> Mathias Gaunard wrote:
>>>> I personally don't understand the point of non-recoverable exceptions
>>>> at all. If they're non recoverable, it means it is something that
>>>> should *never* happen, and therefore is a bug in the program itself.
>>>> The program might as well abort and terminate directly. Trying to
>>>> clean up in the face of something that should never happen in the
>>>> first place cannot work, and might actually lead to even more errors.
>>>
>>> Yes, you're quite right.
>>>
>>> Being able to catch them, however, can make debugging a program easier.
>>
>> Isn't a breakpoint on abort() a better alternative? I wouldn't want any
>> unwinding or object clean-up to occur under those conditions. Along
>> with the risk of more damage being done, valuable state information may
>> be lost.
>
> Usually, yes, a breakpoint is better. But consider what a breakpoint is
> - it's a debugger installing an exception handler! A debugger is
> sometimes not available, and so it's nice to be able to build in a bit
> of debugger capability into the program.

Even if a debugger is not available, on Linux, abort() will leave a core
file that contains the exact state of the frame that caused the problem.
Exception will pop up and leave the frame. Debugging is much easier
with abort(), and it is not equivalent to an exception handler,
since no stack unwinding.

--
Dragan

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Andrew on
On 7 July, 20:16, Walter Bright <newshou...(a)digitalmars.com> wrote:
> Mathias Gaunard wrote:
> > I personally don't understand the point of non-recoverable exceptions
> > at all. If they're non recoverable, it means it is something that
> > should *never* happen, and therefore is a bug in the program itself.
> > The program might as well abort and terminate directly.
> Yes, you're quite right.

I reckon this is true >90% of the time. However, I once (relatively
recently) worked on a program where this was not the case. The program
was a monolithic server with hundreds of clients typically connected
at any one time. There were loads of functions, and yes, some had
bugs. Some of these bugs corresponded to non-recoverable exceptions.
For example, a pointer might be null where not expected. One checks
the pointer and throws a non-recoverable exception if it is null. We
wanted the server to trap this at the point where the top-level
function for the client was invoked. We give an error message to the
client, log the occurence in our log and then carry on, rather than
disconnect the other hundreds of clients.

For this reason, in the implementation of our functionality in the
server, we defined an exception that meant 'a programming error has
been detected'. I think we called it AssertionFailure. We threw this
where other people might have used the C assert macro. We arguments
with some people that it is wrong to continue when you've found a
coding error, but in this case it was much better to keep those
hundreds of users connected.

Regards,

Andrew Marlow

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]