Thread: What is narrowing down?

  1. #1
    zach
    Guest

    What is narrowing down?

    A compile warning is "narrowing down". Is this what it means? I.e., having int as return type whereas passed are shorts. Like so:

    Code:
    int foo(short a, short b)
    {
        some code
    }

  2. #2
    Informer -Adrian's Avatar
    Join Date
    Jan 2013
    Posts
    817
    A narrowing conversion is the inverse of your example, storing a larger type (e.g. an int) in a smaller one (e.g. a short). Since the smaller type cannot represent the entire possible range of values of the larger type, data could be discarded in the conversion.

  3. #3
    zach
    Guest
    Quote Originally Posted by -Adrian View Post
    A narrowing conversion is the inverse of your example, storing a larger type (e.g. an int) in a smaller one (e.g. a short). Since the smaller type cannot represent the entire possible range of values of the larger type, data could be discarded in the conversion.
    Thank you. Don't understand why the compiler came up with that warning then, because that was the situation.

  4. #4
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    678
    Quote Originally Posted by zach View Post
    Thank you. Don't understand why the compiler came up with that warning then, because that was the situation.
    We would need to see the actual code that caused the warning. Calling function, and the function called.

  5. #5
    zach
    Guest
    Quote Originally Posted by rstanley View Post
    We would need to see the actual code that caused the warning. Calling function, and the function called.
    Yes, I understand. Thank you. I need to do more searching myself before I do that. Hence the query I have just now placed.

  6. #6
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,490
    Quote Originally Posted by zach View Post
    Yes, I understand. Thank you. I need to do more searching myself before I do that. Hence the query I have just now placed.
    This thread was closed quite some time ago. Please don't resurrect old threads

  7. #7
    zach
    Guest
    Quote Originally Posted by Hodor View Post
    This thread was closed quite some time ago. Please don't resurrect old threads
    I wasn't aware that I was doing that. I don't like wasting my time in the way you imply. What is more, I had already retracted my query before you responded.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Widening and Narrowing concepts
    By Eman in forum C++ Programming
    Replies: 27
    Last Post: 09-04-2011, 10:06 AM

Tags for this Thread