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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:45:46+00:00 2026-05-27T00:45:46+00:00

The main problem I am facing here is that strtoll() is flagged as an

  • 0

The main problem I am facing here is that strtoll() is flagged as an error in VC 2010 (error C3861: 'strtoll': identifier not found). Will it do the same thing if I replace it with strtol()?

unsigned int get_uintval_from_arg(int argc, int index, char **argv,
                                  unsigned int lower_bound, unsigned int upper_bound) 
{  
    unsigned int return_val=0;

    if (index + 1 <= argc - 1)
    {
        return_val=(unsigned int)strtoll(argv[index+1],NULL,10);
        if (errno == EINVAL || errno== ERANGE) 
        {
            fprintf(stderr, "Could not parse argument %s for switch %s!\n",
                    argv[index], argv[index+1]);
            return 0;
        }
    }
    // ....... I will post the remaining part of the code if necessary 
    .......
}
  • 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-27T00:45:47+00:00Added an answer on May 27, 2026 at 12:45 am

    Since your return_val is an unsigned int, you should probably be using strtoul() which has been standard since C89 and is therefore supported by MSVC (whereas strtoll() has only been standard since C99 and is not supported by MSVC).

    Your testing of the error conditions is not adequate. You need to set errno to zero before calling the conversion function; you also need to detect whether an error was reported, which is trickier than it seems.

    Section §7.20.1.4 ‘The strtol, strtoll, strtoul, and strtoull functions’ of the C99 standard says:

    Returns

    The strtol, strtoll, strtoul, and strtoull functions return the converted
    value, if any. If no conversion could be performed, zero is returned. If the correct value
    is outside the range of representable values, LONG_MIN, LONG_MAX, LLONG_MIN,
    LLONG_MAX, ULONG_MAX, or ULLONG_MAX is returned (according to the return type
    and sign of the value, if any), and the value of the macro ERANGE is stored in errno.

    You also have to read the look at the value stored in the endptr parameter to the conversion functions to tell that no conversion was performed (as opposed to a valid zero was converted).

    If the subject sequence is empty or does not have the expected form, no conversion is
    performed; the value of nptr is stored in the object pointed to by endptr, provided
    that endptr is not a null pointer.

    So, you must write code more like this (omitting the test against EINVAL because the standard does not mention these functions setting errno to EINVAL):

    unsigned int return_val=0;
    
    if (index + 1 <= argc - 1)
    {
        char *end;
        unsigned long ul;
        errno = 0;
        ul = strtoul(argv[index+1], &end, 10);
        if ((ul == 0 && end == argv[index+1]) ||
            (ul == ULONG_MAX && errno == ERANGE) ||
            (ul > UINT_MAX))
        {
            fprintf(stderr, "Could not parse argument %s for switch %s!\n",
                    argv[index], argv[index+1]);
            return 0;
        }
        retval = (unsigned int)ul;
    }
    

    Note that this is simpler than the test for a signed integer conversion which must take into account the negative <type>_MIN limit as well as the <type>_MAX limit.

    Also note that you really should record the result in an unsigned long and then check whether it fits within your designated range, which may be limited to UINT_MAX (which can be less than ULONG_MAX in a Unix-like 64-bit environment).

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

Sidebar

Related Questions

I have a problem that I am facing OuOfMemory Error while printing a string
Edit: I've come to realize the main problem I'm facing is that I want
I'm here facing a problem with a Java web project. The project I'm working
Using backbone.js, here is a quick test to demonstrate the problem I am facing
I am new to Haskell and facing a "cannot construct infinite type" error that
What I am trying to say here is the problem I'm facing to relaunch
I'm facing a very annoying problem. Here's the context : I have a rectangle
The problem I'm facing is that I'm trying to manipulate (in this particular case
It's been now 1 week that I am facing this problem. I'm trying to
Main problem: how do i group elements by their Date, only if continuous and

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.