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 9204937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:49:52+00:00 2026-06-17T23:49:52+00:00

I have been trying to find an answer and get this to work for

  • 0

I have been trying to find an answer and get this to work for a while now and so I figured I’d check here. I am trying to pass a pointer to a long by reference. The syntax I’m using is:

int Hex2Loong(long*& bytebuff, int& len, const std::string Hexbuff);

The error shows up whenever I try to declare the function. The definition itself surprisingly
seems to have no issues. I’m using the same exact syntax with a int*& in my Hex2Int fcn
and there are no problems there. Any ideas what I’m messing up?

The error I’m getting is:
error:in passing argument 1 of Hex2Loong(long int*&,int &,const std::string);

On a related note if I have a unsigned long * I take it there is no way to cast that so I
can pass it into the Hex2Loong function right? I will have to create temporary long *
vars cast into them and pass those?

Ty for any answers,
Drf

Edit:
Hmm ok so to answer some of the comments.
I pass a reference since the function converts a possibly very long hexadecimal string
to an array of longs. (i.e. think a number on the order of 2^1000 written as a hex string)
and I need to pass the number back as an array of longs (I will probably rewrite it for
unsigned longs since the no casting makes it cumbersome).

The HexString is declared as const since it’s supposed to be (it should not be modified only read).

And finally you were quite right the error had nothing to do with the declaration but
rather with the usage. The fact that I was trying to pass (long *) num1 where num1
was unsigned long * was messing everything up. I still don’t get why the error showed
up in the header file though instead of just the place where I was actually calling
the function with the wrong parameters.

Edit2: Ooh I just realized what you meant by passing const std::string&. And of course
you’re exactly right. I will change that aswell. It’s what I get for writing in java
too much. I didn’t realize the string would actually get copied.

  • 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-06-17T23:49:53+00:00Added an answer on June 17, 2026 at 11:49 pm

    You should be able to call that function fine with something like:

    long lvar;
    long *plvar = &lvar;
    int rc = Hex2Loong (plvar, some_int, some_string);
    

    What you can’t do is pass the address of the long, since you need a real reference. In other words, don’t try:

    long lvar;
    int rc = Hex2Loong (&lvar, some_int, some_string);
    

    See the following sample code:

    void Fn (long * &p1) {}
    
    int main (void) {
        long lvar;
        long *plvar = &lvar;
        Fn (plvar);
        //Fn (&lvar);
        return 0;
    }
    

    This compiles okay but complains when you uncomment the &lvar line.


    In terms of your second question, no, you need an actual variable that can be passed as a reference, simply because the function may attempt to change it. So you’ll need to make a temporary copy somewhere.

    However, keep in mind that, unless you actually need to change the value of the variable you’re passing in (so that such a change is reflected in the calling code), there’s no need to pass a reference. You can just pass it by value and use the value within the function.

    If you do that (ie, if you don’t need to change it), you can then use temporaries like &lvar or (long*)(unsigned_long_ptr_variable) in the function call.

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

Sidebar

Related Questions

I have been trying to find some resource on this topic for a while
I have been scouring the web trying to find an answer to this question,
Been trying to find an answer to this but can't seem to get my
Been trying to google an answer but cant seem to find anything, I have
I have been trying to find a solution to this one but could not
I haven't been able to find a good answer to this issue. I'm trying
I have been searching for an answer to this question but could not find
I have been searching for an answer to this for days, and while some
Okay, I've been trying to get this for almost 4 hours now, and it
I have searched up and down trying to find an answer that will work

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.