Sunday, January 26, 2014

comp.lang.c++ - 26 new messages in 4 topics - digest

comp.lang.c++
http://groups.google.com/group/comp.lang.c++?hl=en

comp.lang.c++@googlegroups.com

Today's topics:

* goto label inside of if statement - 8 messages, 6 authors
http://groups.google.com/group/comp.lang.c++/t/7c222b0d5330287c?hl=en
* Link object files from VC++ and GCC? - 10 messages, 4 authors
http://groups.google.com/group/comp.lang.c++/t/d605f2ea0db15eb9?hl=en
* Boost - 7 messages, 5 authors
http://groups.google.com/group/comp.lang.c++/t/81738d66827a11c8?hl=en
* What is the disadvantage with C++ in Embedded systems? - 1 messages, 1
author
http://groups.google.com/group/comp.lang.c++/t/d2c6dd66860beb15?hl=en

==============================================================================
TOPIC: goto label inside of if statement
http://groups.google.com/group/comp.lang.c++/t/7c222b0d5330287c?hl=en
==============================================================================

== 1 of 8 ==
Date: Thurs, Jan 23 2014 7:16 pm
From: Victor Bazarov


On 1/23/2014 6:54 PM, W Karas wrote:
>[..]
> What't the better alternative when you have to break out of an outer
block, or a block that's not the body of a switch or loop?

Throw an exception.

Breaking out of nested loops is the only situation in which it's
reasonable, I think. The easiest thing in that case, however, is to
wrap your loops in a function and 'return' from it. I know, I know, not
the best solution, either, especially considering that you'd need the
context pass in somehow. Perhaps wrap it in a lambda that captures
everything...

V
--
I do not respond to top-posted replies, please don't ask




== 2 of 8 ==
Date: Fri, Jan 24 2014 12:00 am
From: David Brown


On 23/01/14 20:32, W Karas wrote:
> I was surprised to find that this code:
>
> struct A { A(); ~A(); };
>
> void bar();
>
> void foo(bool f)
> {
> if (0)
> {
> LAB: ;
> }
> else
> {
> A a;
>
> if (f) goto LAB;
>
> bar();
> }
> }
>
> will compile without warnings using GCC 4.7.3, even with -Wall and -Wextra .
>
> The point, in case you were wondering, would be a macro-based "named block" pseudo-construct, where the block could be exited from any depth of block nesting, for example:
>
> #define BLOCK(NAME) if (0) { NAME: ; } else
> #define EXITBLOCK(NAME) goto NAME;
>
> struct A { A(); ~A(); };
>
> void bar();
>
> void foo(bool f)
> {
> BLOCK(XYZ)
> {
> A a;
>
> if (f) EXITBLOCK(XYZ)
>
> bar();
> }
> }
>


Such unstructured mixes of control flow /are/ possible in C, and can
sometimes be a good idea. But you need to be /very/ careful about what
you are doing - usually it is not worth the cost in terms of the
confusion you cause yourself and other readers. It is often better to
just duplicate some code sections (either copy-and-paste duplication, or
extracting a function which you might then make "static inline"). If it
is possible to combine the sections safely, then let the compiler's
optimiser do it for you.

You might be interested in looking up "protothreads" for a way of mixing
switches, labels, and other structures in order to make a simple
cooperative multi-threading system. I haven't used it myself, but I
believe it is all legal in C.






== 3 of 8 ==
Date: Fri, Jan 24 2014 1:04 am
From: Stuart


On 04/23/14, W Karas wrote:
> I was surprised to find that this code:
>
> struct A { A(); ~A(); };
>
> void bar();
>
> void foo(bool f)
> {
> if (0)
> {
> LAB: ;
> }
> else
> {
> A a;
>
> if (f) goto LAB;
>
> bar();
> }
> }
>
> will compile without warnings using GCC 4.7.3, even with -Wall and -Wextra .

[snip]

I remember that I read a lot of discussions about whether
http://en.wikipedia.org/wiki/Duff's_device is legal C++ or undefined
behaviour. Even though this is a bit different from your case, maybe
those discussion contain some valuable information for you, too.

Regards,
Stuart





== 4 of 8 ==
Date: Fri, Jan 24 2014 12:30 pm
From: Larry Evans


On 01/23/14 13:32, W Karas wrote:
> I was surprised to find that this code:
>
> struct A { A(); ~A(); };
>
> void bar();
>
> void foo(bool f)
> {
> if (0)
> {
> LAB: ;
> }
> else
> {
> A a;
>
> if (f) goto LAB;
>
> bar();
> }
> }
>
> will compile without warnings using GCC 4.7.3, even with -Wall and -Wextra .
>
> The point, in case you were wondering, would be a macro-based "named block" pseudo-construct, where the block could be exited from any depth of block nesting, for example:
>
> #define BLOCK(NAME) if (0) { NAME: ; } else
> #define EXITBLOCK(NAME) goto NAME;
>
The exit("loop label") statment here:

http://openeuphoria.org/docs/lang_flow.html#_163_exitstatement

sounds similar.

-Larry






== 5 of 8 ==
Date: Fri, Jan 24 2014 1:52 pm
From: Larry Evans


On 01/24/14 14:30, Larry Evans wrote:
> On 01/23/14 13:32, W Karas wrote:
>> I was surprised to find that this code:
>>
>> struct A { A(); ~A(); };
>>
>> void bar();
>>
>> void foo(bool f)
>> {
>> if (0)
>> {
>> LAB: ;
>> }
>> else
>> {
>> A a;
>>
>> if (f) goto LAB;
>>
>> bar();
>> }
>> }
>>
>> will compile without warnings using GCC 4.7.3, even with -Wall and
>> -Wextra .
>>
>> The point, in case you were wondering, would be a macro-based "named
>> block" pseudo-construct, where the block could be exited from any
>> depth of block nesting, for example:
>>
>> #define BLOCK(NAME) if (0) { NAME: ; } else
>> #define EXITBLOCK(NAME) goto NAME;
>>
> The exit("loop label") statment here:
>
> http://openeuphoria.org/docs/lang_flow.html#_163_exitstatement
>
> sounds similar.
>
> -Larry
>
>
Also:

http://goanna.cs.rmit.edu.au/~dale/ada/aln/5_control_structures.html#RTFToC10

However, the main differences is that the exit's are used to exit loops,
not to jump into a branch of an if statement.

-regards,
Larry





== 6 of 8 ==
Date: Sat, Jan 25 2014 12:55 am
From: Stuart


On 1/23/2014, W Karas wrote:
>> What't the better alternative when you have to break out of an outer
>> block, or a block that's not the body of a switch or loop?

on 01/24/14, Victor Bazarov wrote:
> Throw an exception.

-1

Using an exception for "normal" control flow is IMHO a bad design
choice. My wife had to struggle with a real ugly piece of code for over
two weeks where an exception was used to indicate that some algorithm
had to be invoked with different parameters. Really yuk.

I have to admit that using exceptions is tempting, but it makes the
intended control flow harder to "read": If you see the code that throws
the exception it is harder for you to figure out what will be the next
statement because the exception might propagate through multiple levels
on the stack. A plain old return-statement tells you exactly what the
next statement will be.

> Breaking out of nested loops is the only situation in which it's
> reasonable, I think. The easiest thing in that case, however, is to
> wrap your loops in a function and 'return' from it.

+1

This is the technique I prefer, even though premature returns are often
labeled as "GOTO in disguise" by some people (for example my
co-workers). You have to pay the price of having to re-structure your
code so that individual loops have their own function.

> I know, I know, not
> the best solution, either, especially considering that you'd need the
> context pass in somehow. Perhaps wrap it in a lambda that captures
> everything...

Parameter passing should not be such an issue if you make your function
an object. Then you can simply put the parameters that are needed only
in the inner-most loops into a member variable, so there is no need to
"pass through" them from one function to the next.

This is usually not too much of an overkill because algorithms that tend
to need GOTOs are usually more time-consuming beasts, where you want to
be able to give the caller some kind of progress information or some
means to pause/stop the computation, so you will most probably wrap the
algorithm in an object, anyway.

Regards,
Stuart




== 7 of 8 ==
Date: Sat, Jan 25 2014 2:38 am
From: "Alf P. Steinbach"


On 23.01.2014 20:32, W Karas wrote:
> I was surprised to find that this code:
>
> struct A { A(); ~A(); };
>
> void bar();
>
> void foo(bool f)
> {
> if (0)
> {
> LAB: ;
> }
> else
> {
> A a;
>
> if (f) goto LAB;
>
> bar();
> }
> }
>
> will compile without warnings using GCC 4.7.3, even with -Wall and -Wextra.

It's okay to jump across block boundaries with "goto", either into or
out of a block, and it's also okay to jump into block boundaries with a
`switch` (the old "duff's device" relied on that), but you can't

* jump across function boundaries or

* skip the initialization of a variable


> The point, in case you were wondering, would be a macro-based "named block"
> pseudo-construct, where the block could be exited from any depth of block
> nesting, for example:
>
> #define BLOCK(NAME) if (0) { NAME: ; } else
> #define EXITBLOCK(NAME) goto NAME;
>
> struct A { A(); ~A(); };
>
> void bar();
>
> void foo(bool f)
> {
> BLOCK(XYZ)
> {
> A a;
>
> if (f) EXITBLOCK(XYZ)
>
> bar();
> }
> }

That's ingenious.

But, heads-up: there once was a version of a Unix shell written in C
with macros and support functions defined to make it look like Pascal.
Heavy emphasis on **was**.

And for example, when I once defined a WITH macro (corresponding to C#
"using"), and even enlisted help from the community with the quality
assurance of that, I thought this was the next best thing since pizza
slices. It used a similar trick internally, using an `if` to introduce a
variable for the `else` part. I have not used that macro since.

* * *

So, how to reasonably exit from a nested scope, without such shenanigans?

Let's consider the common example, a nested loop, with some nested
conditionals thrown in for good measure, plus an "at the end" action:


[code]
#include <iostream>
#include <math.h> // sqrt
using namespace std;

auto main()
-> int
{
int const max_a = 12345;
int const max_numbers = 42;
int n = 0;
int prev_c = 0;
for( int a = 1; a <= max_a; ++a )
{
for( int b = 1; b < a; ++b )
{
int const c_sq = a*a + b*b;
int const c = int( sqrt( c_sq ) + 0.5 );
if( c*c == c_sq )
{
if( c < prev_c )
{
cout << (n > 0? " " : "") << c;
++n;
if( n == max_numbers )
{
goto finished;
}
}
prev_c = c;
}
}
}
finished:
cout << endl;

cout << "Found " << n << " interesting numbers." << endl;
}
[/code]


The C++ construct that is a scope that can be exited from some nested
scope, is a function, and in most all cases introducing (refactoring as)
a function is a good solution.

In C++03 that function must be a named function or a function template
instantiation. As a named function it can be at namespace scope or a
member of a local class. In C++11 it can also be an anonymous function,
as a lambda.

The code below shows a C++03-style named function refactoring:


[code]
#include <iostream>
#include <math.h> // sqrt
using namespace std;

auto list_interesting_numbers(
int const max_numbers,
int const max_a = 12345
)
-> int
{
int n = 0;
int prev_c = 0;
for( int a = 1; a <= max_a; ++a )
{
for( int b = 1; b < a; ++b )
{
int const c_sq = a*a + b*b;
int const c = int( sqrt( c_sq ) + 0.5 );
if( c*c == c_sq )
{
if( c < prev_c )
{
cout << (n > 0? " " : "") << c;
++n;
if( n == max_numbers )
{
return n;
}
}
prev_c = c;
}
}
}
return n;
}

auto main()
-> int
{
int const n = list_interesting_numbers( 42 );
cout << endl;

cout << "Found " << n << " interesting numbers." << endl;
}
[/code]


Since the `goto` has been eliminated, the effect of any statement here
is clear just from inspecting the statement itself.

Also, the function is more reusable.

For some special cases of nested loops there are some other clean
alternatives. For example, looping over a rectangular set of positions
can be done with a single logical position variable. But I do not think
that the Pascal solution, of introducing extra boolean "are we finished
yet" variables, checked at every loop iteration, is clean for C++. That
solution was nice for Pascal, and also for C, where a single exit point
(SESE) is important. However, in C++ a single exit point can almost
never be relied on (so that code that does, is misguided), and one has
tools to deal with multiple exit points, namely destructors and `catch`.


Cheers & hth.,

- Alf





== 8 of 8 ==
Date: Sat, Jan 25 2014 7:15 am
From: Jax


Mr Flibble <flibbleREMOVE_THIS_AND_THIS@i42.co.uk> wrote in news:0s-
dnV4ZKKKpMnzPnZ2dnUVZ7oidnZ2d@giganews.com:

> On 24/01/2014 00:08, Mr Flibble wrote:
>> On 23/01/2014 23:54, W Karas wrote:
>>> On Thursday, January 23, 2014 5:56:34 PM UTC-5, Mr Flibble wrote:
>>>> On 23/01/2014 19:32, W Karas wrote:
>>>>
>>>>
>>>>
>>>>> #define BLOCK(NAME) if (0) { NAME: ; } else
>>>>
>>>>> #define EXITBLOCK(NAME) goto NAME;
>>>>
>>>>>
>>>>
>>>>> struct A { A(); ~A(); };
>>>>
>>>>>
>>>>
>>>>> void bar();
>>>>
>>>>>
>>>>
>>>>> void foo(bool f)
>>>>
>>>>> {
>>>>
>>>>> BLOCK(XYZ)
>>>>
>>>>> {
>>>>
>>>>> A a;
>>>>
>>>>>
>>>>
>>>>> if (f) EXITBLOCK(XYZ)
>>>>
>>>>>
>>>>
>>>>> bar();
>>>>
>>>>> }
>>>>
>>>>> }
>>>>
>>>>
>>>>
>>>> That code is awful mate, don't do it.
>>>>
>>>>
>>>>
>>>> /Flibble
>>>
>>> What't the better alternative when you have to break out of an outer
>>> block, or a block that's not the body of a switch or loop?
>>
>> It is awful because breaking out of a bock that's not the body of a
>> switch or loop is awful.
>
> Hiding goto inside a macro does not make goto any less bad. The only
> acceptable use of goto is to break out of a deeply nested loop.
>
> /Flibble

I'm starting to learn C++ and the first example of GOTO I saw went round
and round in an endless loop. That's not very good!

--
Jax :)





==============================================================================
TOPIC: Link object files from VC++ and GCC?
http://groups.google.com/group/comp.lang.c++/t/d605f2ea0db15eb9?hl=en
==============================================================================

== 1 of 10 ==
Date: Fri, Jan 24 2014 12:34 am
From: "Hans-Peter"



"Rick C. Hodgin" wrote in message
news:0f20b7fc-b6b1-46d6-a733-bff0636cb5a7@googlegroups.com...
>
> Is there a way to link object files between Visual C++ and GCC?
>
> I have some data that I need to encode like this:
> char* list[] = {
> "one",
> "two",
> "three",
> };
>
> Unfortunately, by default, the list[0], list[1], and list[2] pointers
> point
> to data that's in read-only memory. Any attempt to do something like
> memcpy(list[0], "eno", 3) fails with "Access Violation" on Windows.

You can force that the list will be in the data segment by using #pragma
data_seg() but this will only move the pointer array in to the data segment.
Changing the strings to fixed size will do the job:

#pragma data_seg()
char list[3][6] = {
{ "one" },
{ "two" },
{ "three"}
};

BTW the compiler will throw an error if you set the array dimensions too
small.

Best regards
Hans-Peter





== 2 of 10 ==
Date: Fri, Jan 24 2014 5:49 am
From: "Rick C. Hodgin"


On Friday, January 24, 2014 3:34:26 AM UTC-5, Hans-Peter wrote:
> "Rick C. Hodgin" wrote in message
> > Is there a way to link object files between Visual C++ and GCC?
> > I have some data that I need to encode like this:
> > char* list[] = {
> > "one",
> > "two",
> > "three",
> > };
> > Unfortunately, by default, the list[0], list[1], and list[2] pointers
> > point to data that's in read-only memory. Any attempt to do
> > something like memcpy(list[0], "eno", 3) fails with "Access Violation"
> > on Windows.
>
> You can force that the list will be in the data segment by using #pragma
> data_seg() but this will only move the pointer array in to the data segment.
> Changing the strings to fixed size will do the job:
> #pragma data_seg()
> char list[3][6] = {
> { "one" },
> { "two" },
> { "three"}
> };
>
> BTW the compiler will throw an error if you set the array dimensions too
> small.

Hans-Peter, thank you for your response. I had considered using the [6]
add-on. The actual implementation is about 100 lines, which are source
code lines from another computer language. The lines vary in length from
a few characters up to over 80, the average probably being 15. I had
decided against using the [85] so as to not waste memory.

I like this new solution, as it not only allows me to do my simple list[]
thing, but also to use GCC and VC++ together.

FWIW, I'm not using the GCC/VC++ solution for my project. The original
solution I found is working just fine. :-) This whole thing has been
more of a mental exercise to try to find an alternate course.

Best regards,
Rick C. Hodgin




== 3 of 10 ==
Date: Fri, Jan 24 2014 6:31 am
From: Victor Bazarov


On 1/24/2014 8:49 AM, Rick C. Hodgin wrote:
> [..] The actual implementation is about 100 lines, which are source
> code lines from another computer language. The lines vary in length from
> a few characters up to over 80, the average probably being 15. I had
> decided against using the [85] so as to not waste memory.
> [..]

Just curious, in what world a few hundred bytes is a waste of memory
worthy of consideration? Are you targetting an embedded system or a
legacy computer with 640K memory (last century technology)? Don't get
me wrong, please, it's just that I have often enough seen real
(significant) time wasted on finding a solution to save a few
microseconds or a few [hundred] bytes, that usually in the end cannot be
accounted for. I can understand when students do that in the course of
their studies, but I don't understand the need for it when creating a
product for others to consume.

V
--
I do not respond to top-posted replies, please don't ask




== 4 of 10 ==
Date: Fri, Jan 24 2014 7:53 am
From: "Rick C. Hodgin"


On Friday, January 24, 2014 9:31:40 AM UTC-5, Victor Bazarov wrote:
> On 1/24/2014 8:49 AM, Rick C. Hodgin wrote:
> > [..] The actual implementation is about 100 lines, which are source
> > code lines from another computer language. The lines vary in length from
> > a few characters up to over 80, the average probably being 15. I had
> > decided against using the [85] so as to not waste memory.
> > [..]
>
> Just curious, in what world a few hundred bytes is a waste of memory
> worthy of consideration? Are you targetting an embedded system or a
> legacy computer with 640K memory (last century technology)? Don't get
> me wrong, please, it's just that I have often enough seen real
> (significant) time wasted on finding a solution to save a few
> microseconds or a few [hundred] bytes, that usually in the end cannot be
> accounted for. I can understand when students do that in the course of
> their studies, but I don't understand the need for it when creating a
> product for others to consume.

I'm getting a lot of flack over this from many people on many lists. It's
like ... if I don't do it the way everybody else does then I'm the one who's
wrong. And because I look toward things which are important to me, and
because I choose to not waste memory where it doesn't need to be wasted,
while also simplifying the source code implementation of this task, that
it is somehow a bad choice.

FWIW, I had a working solution after getting the first access violation error
in the Visual Studio debugger and realizing why I got it. It took me a few
seconds to realize what was happening, even though it was unexpected. But,
the whole issue was one of those things I wanted to better understand. It
seemed (and still seems) a very silly imposition, that string literals
created in that way (as data pointed to in a read-write array) should always
be read-only unless they are explicitly cast through such a clunky syntax as
compound literals, a feature that not all C compilers even support.

It was a mental exercise as much as anything else, a pursuit of a question,
to satiate curiosity. I wound up not using the solution, but just
discovering and testing it out. I learned many things in the process, not
the least of which was how to integrate GCC and Visual C++ together in
harmony. That alone was worth all the time I spent on it.

> I do not respond to top-posted replies, please don't ask

Just curious, in what world would you deny giving help to someone in need
simply because they top-posted? I had someone in 2011 or 2012 on the
Trisquel mailing list tell me that I was a top poster and that he
wasn't going to help me. I didn't even know what he was talking about
and had to ask what that phrase "top poster" meant. When I found out
I was floored that such a ridiculous barrier exists between the
help-seekers, and the knowledge-holders on a forum like this.

It really taught me something ... a concept that is so amazingly important
to only a select few, those who desire to divide people into groups of
"them" (top posters) and "us" (the sensible lot). Seeing your tagline here
in this forum I was again floored. I almost wrote something to you about
it yesterday.

Just so you know ... there's a better way, Victor. It's called "love".
Tear down the barriers and come out and help people in love. And if you
want to learn the fulness of love ... He is the man, named Jesus, who is
the Christ, the only Savior of mankind.

Best regards,
Rick C. Hodgin




== 5 of 10 ==
Date: Fri, Jan 24 2014 8:44 am
From: Victor Bazarov


On 1/24/2014 10:53 AM, Rick C. Hodgin wrote:
> On Friday, January 24, 2014 9:31:40 AM UTC-5, Victor Bazarov wrote:
>> On 1/24/2014 8:49 AM, Rick C. Hodgin wrote:
>>> [..] The actual implementation is about 100 lines, which are source
>>> code lines from another computer language. The lines vary in length from
>>> a few characters up to over 80, the average probably being 15. I had
>>> decided against using the [85] so as to not waste memory.
>>> [..]
>>
>> Just curious, in what world a few hundred bytes is a waste of memory
>> worthy of consideration? Are you targetting an embedded system or a
>> legacy computer with 640K memory (last century technology)? Don't get
>> me wrong, please, it's just that I have often enough seen real
>> (significant) time wasted on finding a solution to save a few
>> microseconds or a few [hundred] bytes, that usually in the end cannot be
>> accounted for. I can understand when students do that in the course of
>> their studies, but I don't understand the need for it when creating a
>> product for others to consume.
>
> I'm getting a lot of flack over this from many people on many lists. It's
> like ... if I don't do it the way everybody else does then I'm the one who's
> wrong. And because I look toward things which are important to me, and
> because I choose to not waste memory where it doesn't need to be wasted,
> while also simplifying the source code implementation of this task, that
> it is somehow a bad choice.

No, not a bad choice, by any means IMO. Just an uncommon one.
Everybody has their priorities. Advice we *give* in part serves as
affirmation of our being right (or at least in the right area). If
something is recommended against our convictions, we have a choice -
either to change our convictions or ignore the advice. And we make
those choices constantly. Such is life.

> FWIW, I had a working solution after getting the first access violation error
> in the Visual Studio debugger and realizing why I got it. It took me a few
> seconds to realize what was happening, even though it was unexpected. But,
> the whole issue was one of those things I wanted to better understand. It
> seemed (and still seems) a very silly imposition, that string literals
> created in that way (as data pointed to in a read-write array) should always
> be read-only unless they are explicitly cast through such a clunky syntax as
> compound literals, a feature that not all C compilers even support.

I hope you don't have to learn the hard way why such a silly imposition
exists.

> It was a mental exercise as much as anything else, a pursuit of a question,
> to satiate curiosity. I wound up not using the solution, but just
> discovering and testing it out. I learned many things in the process, not
> the least of which was how to integrate GCC and Visual C++ together in
> harmony. That alone was worth all the time I spent on it.

No argument here. Even if we don't gain anything, we always gain
experience.

>> I do not respond to top-posted replies, please don't ask
>
> Just curious, in what world would you deny giving help to someone in need
> simply because they top-posted? I had someone in 2011 or 2012 on the
> Trisquel mailing list tell me that I was a top poster and that he
> wasn't going to help me. I didn't even know what he was talking about
> and had to ask what that phrase "top poster" meant. When I found out
> I was floored that such a ridiculous barrier exists between the
> help-seekers, and the knowledge-holders on a forum like this.

It's my help to give, I can and may deny it on any basis I choose.
Would you help somebody who speaks rudely to you in the street or would
you simply turn away and keep minding your own business? In such a case
rudeness is in the eye of the beholder, of course. Similarly, I
perceive top-posting as rudeness and choose not to involve myself in a
message thread like that.

Incidentally, a way to have the last word in an argument with me *here*
is to top-post.

> It really taught me something ... a concept that is so amazingly important
> to only a select few, those who desire to divide people into groups of
> "them" (top posters) and "us" (the sensible lot). Seeing your tagline here
> in this forum I was again floored. I almost wrote something to you about
> it yesterday.
>
> Just so you know ... there's a better way, Victor. It's called "love".

Yes. So, if you care for *my* reply, now that you know that it is
important to *me*, and you can't get it if you top-post, you *might*
want to consider not top-post. Get it?

Practice what you preach.

And try not to preach.

> Tear down the barriers and come out and help people in love. And if you
> want to learn the fulness of love ... He is the man, named Jesus, who is
> the Christ, the only Savior of mankind.

<sigh>

V
--
I do not respond to top-posted replies, please don't ask




== 6 of 10 ==
Date: Fri, Jan 24 2014 9:40 am
From: Paavo Helde


"Hans-Peter" <Hans-Peter.Rampp@sap.com> wrote in
news:lbt8ip$dos$1@news.sap-ag.de:

>
> "Rick C. Hodgin" wrote in message
> news:0f20b7fc-b6b1-46d6-a733-bff0636cb5a7@googlegroups.com...
>>
>> Is there a way to link object files between Visual C++ and GCC?
>>
>> I have some data that I need to encode like this:
>> char* list[] = {
>> "one",
>> "two",
>> "three",
>> };
>>
>> Unfortunately, by default, the list[0], list[1], and list[2] pointers
>> point
>> to data that's in read-only memory. Any attempt to do something like
>> memcpy(list[0], "eno", 3) fails with "Access Violation" on Windows.
>
> You can force that the list will be in the data segment by using
> #pragma data_seg() but this will only move the pointer array in to the
> data segment. Changing the strings to fixed size will do the job:

Seems it affects string literals as well. This program works fine for me
with VS2012:

#include <iostream>

#pragma data_seg(".xxx")

char* list[] = {
"one",
"two",
"three"};

int main() {
list[0][0]='t';
list[0][1]='e';
list[0][2]='n';
std::cout << list[0] << "\n";
}

Cheers
Paavo







== 7 of 10 ==
Date: Fri, Jan 24 2014 10:12 am
From: "Rick C. Hodgin"


On Friday, January 24, 2014 12:40:33 PM UTC-5, Paavo Helde wrote:
> Seems it affects string literals as well. This program works fine for me
> with VS2012:
>
> #include <iostream>
> #pragma data_seg(".xxx")
> char* list[] = {
> "one",
> "two",
> "three"
> };
> int main()
> {
> list[0][0]='t';
> list[0][1]='e';
> list[0][2]='n';
> std::cout << list[0] << "\n";
> }

Paavo, this one of the suggestions I tried. In VS2008 it gives the
same access violation error.

Best regards,
Rick C. Hodgin




== 8 of 10 ==
Date: Fri, Jan 24 2014 10:14 am
From: "Rick C. Hodgin"


On Friday, January 24, 2014 11:44:40 AM UTC-5, Victor Bazarov wrote:
> Yes. So, if you care for *my* reply, now that you know that it is
> important to *me*, and you can't get it if you top-post, you *might*
> want to consider not top-post. Get it?

Did I top-post? I ask because I honestly don't know. I was under the
impression that top-posting meant you posted above the quoted content.
But maybe my understanding is still incorrect.

Best regards,
Rick C. Hodgin




== 9 of 10 ==
Date: Fri, Jan 24 2014 10:33 am
From: Victor Bazarov


On 1/24/2014 1:14 PM, Rick C. Hodgin wrote:
> On Friday, January 24, 2014 11:44:40 AM UTC-5, Victor Bazarov wrote:
>> Yes. So, if you care for *my* reply, now that you know that it is
>> important to *me*, and you can't get it if you top-post, you *might*
>> want to consider not top-post. Get it?
>
> Did I top-post? I ask because I honestly don't know. I was under the
> impression that top-posting meant you posted above the quoted content.
> But maybe my understanding is still incorrect.

You did not top-post.

V
--
I do not respond to top-posted replies, please don't ask




== 10 of 10 ==
Date: Fri, Jan 24 2014 10:39 am
From: Victor Bazarov


On 1/24/2014 1:12 PM, Rick C. Hodgin wrote:
> On Friday, January 24, 2014 12:40:33 PM UTC-5, Paavo Helde wrote:
>> Seems it affects string literals as well. This program works fine for me
>> with VS2012:
>>
>> #include <iostream>
>> #pragma data_seg(".xxx")
>> char* list[] = {
>> "one",
>> "two",
>> "three"
>> };
>> int main()
>> {
>> list[0][0]='t';
>> list[0][1]='e';
>> list[0][2]='n';
>> std::cout << list[0] << "\n";
>> }
>
> Paavo, this one of the suggestions I tried. In VS2008 it gives the
> same access violation error.

VS2010 does the same. VS2012 differs - the resulting program runs OK.
I don't know whether it's a good idea for you to switch to VS2012 at
this point. This is obviously implementation-specific.

V
--
I do not respond to top-posted replies, please don't ask





==============================================================================
TOPIC: Boost
http://groups.google.com/group/comp.lang.c++/t/81738d66827a11c8?hl=en
==============================================================================

== 1 of 7 ==
Date: Fri, Jan 24 2014 9:01 am
From: Oscar Chesnutt


J. Clarke wrote:

>> Please leave this thread, you do not contribute in any way.
>
> <plonk>

Indeed, this supposedly means that you gonna use a computer program
helping you not to read. Otherwise you just keep reading. You must be
terribly clever, like your friends.

We never got the answer to the Boost concern. Do I have to be stupid to
use that?




== 2 of 7 ==
Date: Fri, Jan 24 2014 9:33 am
From: Daniel


On Friday, January 24, 2014 12:01:15 PM UTC-5, Oscar Chesnutt wrote:
>
> We never got the answer to the Boost concern. Do I have to be
> stupid to use that?

Not at all. Even if you are not stupid, you can still use it.
Hope that helps.

Daniel





== 3 of 7 ==
Date: Fri, Jan 24 2014 2:14 pm
From: Jorgen Grahn


On Fri, 2014-01-24, Oscar Chesnutt wrote:
> J. Clarke wrote:
>
>>> Please leave this thread, you do not contribute in any way.
>>
>> <plonk>
>
> Indeed, this supposedly means that you gonna use a computer program
> helping you not to read. Otherwise you just keep reading. You must be
> terribly clever, like your friends.
>
> We never got the answer to the Boost concern. Do I have to be stupid to
> use that?

Are you insulting people, nym-shifting and whatnot, and /still/ expect
people to discuss Boost with you? Seriously?

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .




== 4 of 7 ==
Date: Sat, Jan 25 2014 1:04 am
From: Oscar Chesnutt


Jorgen Grahn wrote:

>> We never got the answer to the Boost concern. Do I have to be stupid to
>> use that?
>
> Are you insulting people, nym-shifting and whatnot, and /still/ expect
> people to discuss Boost with you? Seriously?

What nym-shifting and what insulting, are you serious??

From what I read in this thread you and your likes are insulting by not
relating to the issues, calling people "trolls", "nym-shifters" and so on.

Plonk also is just another insult, otherwise if applied literary would
imply feeding a computer program or algorithm with a file, helping the
owner NOT TO READ in and usenet forum.

Are you going to debate semantics or talk about the issue indicated by the
subject line.

You and your "friends" are violating the unwritten rules of usenet. Take
care.




== 5 of 7 ==
Date: Sat, Jan 25 2014 3:17 am
From: Jorgen Grahn


On Sat, 2014-01-25, Oscar Chesnutt wrote:
> Jorgen Grahn wrote:
>
>>> We never got the answer to the Boost concern. Do I have to be stupid to
>>> use that?
>>
>> Are you insulting people, nym-shifting and whatnot, and /still/ expect
>> people to discuss Boost with you? Seriously?
>
> What nym-shifting and what insulting, are you serious??

As far as I can tell, you are posting in this thread as (at least)
Nick Baumbach
Walter Profile
Bob Hammerman
Oscar Chesnutt
That's the definition of nym-shifting, ok?

If you stop doing that, I'm prepared to discuss Boost[1] -- it
doesn't have diplomatic immunity or anything, and we're allowed to
criticize or defend it.

/Jorgen

[1] Except I personally don't have any real experience,
so I can only comment on the barriers to adopting it --
like trying to read up on some library and giving up
when I don't understand anything after 20 minutes.

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .




== 6 of 7 ==
Date: Sat, Jan 25 2014 6:46 am
From: "J. Clarke"


In article <slrnle77a3.81f.grahn+nntp@frailea.sa.invalid>,
grahn+nntp@snipabacken.se says...
>
> On Sat, 2014-01-25, Oscar Chesnutt wrote:
> > Jorgen Grahn wrote:
> >
> >>> We never got the answer to the Boost concern. Do I have to be stupid to
> >>> use that?
> >>
> >> Are you insulting people, nym-shifting and whatnot, and /still/ expect
> >> people to discuss Boost with you? Seriously?
> >
> > What nym-shifting and what insulting, are you serious??
>
> As far as I can tell, you are posting in this thread as (at least)
> Nick Baumbach
> Walter Profile
> Bob Hammerman
> Oscar Chesnutt
> That's the definition of nym-shifting, ok?
>
> If you stop doing that, I'm prepared to discuss Boost[1] -- it
> doesn't have diplomatic immunity or anything, and we're allowed to
> criticize or defend it.
>
> /Jorgen
>
> [1] Except I personally don't have any real experience,
> so I can only comment on the barriers to adopting it --
> like trying to read up on some library and giving up
> when I don't understand anything after 20 minutes.

And that's its real failing--like much else computer related the
documentation sucks bigtime.






== 7 of 7 ==
Date: Sat, Jan 25 2014 8:27 am
From: woodbrian77@gmail.com


On Saturday, January 25, 2014 8:46:15 AM UTC-6, J. Clarke wrote:
> In article <slrnle77a3.81f.grahn+nntp@frailea.sa.invalid>,
>
> grahn+nntp@snipabacken.se says...
> >
>
> > [1] Except I personally don't have any real experience,
> > so I can only comment on the barriers to adopting it --
> > like trying to read up on some library and giving up
> > when I don't understand anything after 20 minutes.
>
> And that's its real failing--like much else computer related the
> documentation sucks bigtime.

I could use some help with my documentation...
If you have some specific ideas on how to improve my
documentation please let me know. (And yes, the software
does support some of Boost.)

Brian
Ebenezer Enterprises -
"Ask and it will be given to you; seek and you will find;
knock and the door will be opened to you.' Matthew 7:7
http://webEbenezer.net





==============================================================================
TOPIC: What is the disadvantage with C++ in Embedded systems?
http://groups.google.com/group/comp.lang.c++/t/d2c6dd66860beb15?hl=en
==============================================================================

== 1 of 1 ==
Date: Sat, Jan 25 2014 8:48 am
From: deepadivakaruni@gmail.com


i think so c++ is more complicated when compared to c.And also the many keywords are used to perform only one application.




==============================================================================

You received this message because you are subscribed to the Google Groups "comp.lang.c++"
group.

To post to this group, visit http://groups.google.com/group/comp.lang.c++?hl=en

To unsubscribe from this group, send email to comp.lang.c+++unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.c++/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

No comments: