Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 842703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:00:28+00:00 2026-05-15T06:00:28+00:00

I’m having difficulty using reinterpret_cast. Lets just say right off the bat that I’m

  • 0

I’m having difficulty using reinterpret_cast. Lets just say right off the bat that I’m not married ot reinterpret_cast. Feel free to suggest major changes. Before I show you my code I’ll let you know what I’m trying to do.

I’m trying to get a filename from a vector full of data being used by a MIPS I processor I designed. Basically what I do is compile a binary from a test program for my processor, dump all the hex’s from the binary into a vector in my c++ program, convert all of those hex’s to decimal integers and store them in a DataMemory vector which is the data memory unit for my processor. I also have instruction memory. So When my processor runs a SYSCALL instruction such as “Open File” my C++ operating system emulator receives a pointer to the beginning of the filename in my data memory. So keep in mind that data memory is full of ints, strings, globals, locals, all sorts of stuff. When I’m told where the filename starts I do the following:

Convert the whole decimal integer element that is being pointed to to its ASCII character representation, and then search from left to right to see if the string terminates, if not then just load each character consecutively into a “filename” string. Do this until termination of the string in memory and then store filename in a table. My difficulty is generating filename from my memory.

Here is an example of what I’m trying to do:

C++ Syntax (Toggle Plain Text)

   1.Index Vector     NewVector   ASCII    filename
   2.0     240faef0   128123792   'abc7'   'a'
   3.0     240faef0   128123792   'abc7'   'ab'
   4.0     240faef0   128123792   'abc7'   'abc'
   5.0     240faef0   128123792   'abc7'   'abc7'
   6.1     1234567a   243225      'k2s0'   'abc7k'
   7.1     1234567a   243225      'k2s0'   'abc7k2'
   8.1     1234567a   243225      'k2s0'   'abc7k2s'
   9.            //EXIT LOOP//
  10.1     1234567a   243225      'k2s0'   'abc7k2s'

Here is the code that I’ve written so far to get filename (I’m just applying this to element 1000 of my DataMemory vector to test functionality. 1000 is arbitrary.):
C++ Syntax (Toggle Plain Text)

   1.int i = 0;
   2.int step = 1000;//top->a0;
   3.string filename;
   4.char *temp = reinterpret_cast<char*>( DataMemory[1000] );//convert to char
   5.cout << "a0:" << top->a0 << endl;//pointer supplied
   6.cout << "Data:" << DataMemory[top->a0] << endl;//my vector at pointed to location
   7.cout << "Data(1000):" << DataMemory[1000] << endl;//the element I'm testing
   8.cout << "Characters:" << &temp << endl;//my temporary char array
   9.
  10.while(&temp[i]!=0)
  11.{
  12.     filename+=temp[i];//add most recent non-terminated character to string
  13.     i++;
  14.     if(i==4)//when 4 characters have been added..
  15.     {
  16.          i=0;
  17.          step+=1;//restart loop at the next element in DataMemory
  18.          temp = reinterpret_cast<char*>( DataMemory[step] );
  19.     }
  20. }
  21. cout << "Filename:" << filename << endl;

So the issue is that when I do the conversion of my decimal element to a char array I assume that 8 hex #’s will give me 4 characters. Why isn’t this this case? Here is my output:

C++ Syntax (Toggle Plain Text)

   1.a0:0
   2.Data:0
   3.Data(1000):4428576
   4.Characters:0x7fff5fbff128
   5.Segmentation fault
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T06:00:28+00:00Added an answer on May 15, 2026 at 6:00 am

    If your strings are null-terminated, don’t you want to do

    10. while(temp[i]!=0)

    instad of

    10. while(&temp[i]!=0)

    Not sure I understand the DataMemory structure though…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need a function that will clean a strings' special characters. I do NOT
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.