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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:35:02+00:00 2026-06-10T15:35:02+00:00

I have some inherited code for FlexLM that is converting an integer to a

  • 0

I have some inherited code for FlexLM that is converting an integer to a pointer that needs to work on both 32bit and 64bit machines. The integer is being filled in from argc of the arguments to the program using scanf to read the integer value.

How should I reliably read the argc string to get a value suitable for assigning to a pointer so that it works on both 32bit and 64bit machines?

Presently the code looks something like this:

// FlexLM includes this:
typedef char * LM_A_VAL_TYPE; /* so that it will be big enough for */
                              /* any data type on any system */

// My main() includes this:
[...]
if (!strcmp(argv[i], "-maxlen")) {
  int max = 0;
  i++;

  if (i >= argc) {
    break;
  }
  sscanf(argv[i], "%d", &max);
  if (!max) {
    fprintf(stderr, "Error: -maxlen %s Invalid line length\n", argv[i]);
  } else {
    lc_set_attr(lm_job, LM_A_MAX_LICENSE_LEN, (LM_A_VAL_TYPE)max);
  }
}
[...]

At first I was thinking I could use uintptr_t, but how would I get scanf to know the size accordingly? Perhaps I should just read it as a pointer value using %p, but the man page gives me doubts about it working reliably:

   p      Matches an implementation-defined set of sequences, which shall be the
          same as the set of sequences that is produced by the %p  conversion
          specification  of  the  corresponding fprintf()  functions.  The
          application  shall  ensure that the corresponding argument is a pointer
          to a pointer to void. The interpretation of the input item is
          implementation-defined. If the input item is a value converted earlier
          during the same program execution, the pointer that results shall
          compare equal to that value; otherwise, the behavior of the %p
          conversion specification is undefined.

I’d rather not use #ifdef to make two separate versions based on pointer size as that seems like an ugly wart on the code to me.

  • 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-10T15:35:04+00:00Added an answer on June 10, 2026 at 3:35 pm

    C99 inttypes.h is supposed to define a macro SCNuPTR which is the correct scanf format specifier to use for uintptr_t arguments on your platform.

    uintptr_t intptr = 0;
    sscanf(argv[i], SCNuPTR, &intptr);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have inherited some code which involves a scheduled task that writes data (obtained
I have inherited some really old VC6.0 code that I am upgrading to VS2008
I have some ASP code that I've inherited from my predecessor (no, it's not
I have inherited some code that queries a DB over a WCF service and
I have inherited some code that isn't quite working ... I have jsp which
I have inherited some code that is not working as I think it should:
I have some code I inherited which has a lot of warnings that I
I have some code that I have inherited that generates a matrix of significance
I have some inherited code that I am modifying. However, I am seeing something
I inherited some partially complete sql code that I can't get to work. it

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.