Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Link object files from VC++ and GCC?

Reply
Thread Tools

Link object files from VC++ and GCC?

 
 
Rick C. Hodgin
Guest
Posts: n/a
 
      01-24-2014
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
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      01-24-2014
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
 
Reply With Quote
 
 
 
 
Rick C. Hodgin
Guest
Posts: n/a
 
      01-24-2014
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
 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      01-24-2014
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
 
Reply With Quote
 
Rick C. Hodgin
Guest
Posts: n/a
 
      01-24-2014
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
 
Reply With Quote
 
Rick C. Hodgin
Guest
Posts: n/a
 
      01-24-2014
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
 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      01-24-2014
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
 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      01-24-2014
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
 
Reply With Quote
 
Öö Tiib
Guest
Posts: n/a
 
      01-25-2014
On Friday, 24 January 2014 15:49:53 UTC+2, Rick C. Hodgin wrote:
> On Friday, January 24, 2014 3:34:26 AM UTC-5, Hans-Peter wrote:
>
> > 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.


So it is 8500 characters that you want to be mutable. You likely get
better memory usage AND better performance with array (or 'std::array')
of 'std::string's, but 8k of data are usually not worth of tinkering
unless you have hundreds of such.
 
Reply With Quote
 
Rick C. Hodgin
Guest
Posts: n/a
 
      01-25-2014
On Saturday, January 25, 2014 12:01:43 PM UTC-5, Öö Tiib wrote:
> On Friday, 24 January 2014 15:49:53 UTC+2, Rick C. Hodgin wrote:
> > On Friday, January 24, 2014 3:34:26 AM UTC-5, Hans-Peter wrote:
> > > 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.

>
> So it is 8500 characters that you want to be mutable. You likely get
> better memory usage AND better performance with array (or 'std::array')
> of 'std::string's, but 8k of data are usually not worth of tinkering
> unless you have hundreds of such.


I have constraints on my design. I am currently writing a compiler that
takes some aspects of C and C++, but I will not support std::array or
std::string. As such, I am looking at some more fundamental approaches
to processing data as I intend eventually to compile my C code in my own
language.

My pursuit here to have the char* list[] array point to a list of read-write
values, instead of read-only values, also looks to that future of my compiler
design.

Best regards,
Rick C. Hodgin
 
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
query from sqlalchemy returns AttributeError: 'NoneType' object karthik.sharma@gmail.com Python 2 05-02-2013 11:29 PM
Re: Best way to get large files from a friend? nospam Digital Photography 0 04-10-2013 07:25 PM
Re: Best way to get large files from a friend? Dave Digital Photography 0 04-10-2013 07:13 PM
Re: Best way to get large files from a friend? nospam Digital Photography 1 04-10-2013 05:51 PM
Re: Best way to get large files from a friend? (PeteCresswell) Digital Photography 0 04-10-2013 03:39 PM



Advertisments