warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data

This is a discussion on warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data within the C Programming forums, part of the General Programming Boards category; hi working on a project, and VS2005 is giving me this warning: - warning C4267: '=' : conversion from 'size_t' ...

  1. #1
    Registered User IndioDoido's Avatar
    Join Date
    Apr 2007
    Posts
    194

    warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data

    hi

    working on a project, and VS2005 is giving me this warning:
    - warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data

    the warning leads here:
    Code:
    tam = strlen(texto[n]);
    can anyone tell me how to "fix" this warning?
    Last edited by IndioDoido; 05-09-2007 at 09:02 PM.
    "Artificial Intelligence usually beats natural stupidity."

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Use size_t as your variable type instead of int.

    Code:
    size_t len;
    ...
    len = strlen("bleh");

  3. #3
    Registered User IndioDoido's Avatar
    Join Date
    Apr 2007
    Posts
    194
    hey MacGyver!

    i did what you said, but now it's giving me this warning:
    - warning C4018: '<' : signed/unsigned mismatch

    and now the warning leads here:
    Code:
    for(l=0; l<(71-tam); l++)
    ??
    "Artificial Intelligence usually beats natural stupidity."

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    903
    I bet you haven't set l as a size_t as well.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    If l is already an unsigned type, then it might be worrying about 71-tam possibly being negative. You can always rewrite the condition like this:
    Code:
    for (l=0; 1+tam<71; l++)

  6. #6
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    582
    Quote Originally Posted by robatino View Post
    If l is already an unsigned type, then it might be worrying about 71-tam possibly being negative. You can always rewrite the condition like this:
    Code:
    for (l=0; 1+tam<71; l++)
    Or like this, a more optimized version:

    Code:
    for (l=0; tam<=71; l++)
    High elevation is the best elevation. The higher, the better the view!
    My computer: XP Pro SP3, 3.4 GHz i7-2600K CPU (OC'd to 4 GHz), 4 GB DDR3 RAM, X-Fi Platinum sound, GeForce 460, 1920x1440 resolution, 1250 GB HDD space, Visual C++ 2008 Express

  7. #7
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    I think this is why you should never use lower case 'L' as a variable name if you can help it.

  8. #8
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    I agree, use an uppercase 'i' instead

  9. #9
    Registered User IndioDoido's Avatar
    Join Date
    Apr 2007
    Posts
    194
    hey you all!

    i havent set 'l' as site_t, i'm going to try that, and if doesn't work i'm going to apply one these versions

    Code:
    for (l=0; 1+tam<71; l++)
    Code:
    for (l=0; tam<=71; l++)
    "Artificial Intelligence usually beats natural stupidity."

  10. #10
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    The second version is wrong (I guess you didn't get the joke).

  11. #11
    Registered User IndioDoido's Avatar
    Join Date
    Apr 2007
    Posts
    194
    ehehe!
    I know it was :P

    i've seted the variables to size_t and it worked...tnx alot guys!

    buy the way, what does this warning mean?
    - warning C4013: 'menuLogin' undefined; assuming extern returning int

    every time i reference a function that warning apears
    "Artificial Intelligence usually beats natural stupidity."

  12. #12
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,230
    Quote Originally Posted by IndioDoido View Post
    buy the way, what does this warning mean?
    - warning C4013: 'menuLogin' undefined; assuming extern returning int

    every time i reference a function that warning apears
    It means you have no prototypes, or you are not including the .h where the prototypes are.

  13. #13
    Registered User IndioDoido's Avatar
    Join Date
    Apr 2007
    Posts
    194
    hi brewbuck!

    i've done what you said, and it worked with the menuLogin function. But with the other functions it didn't
    know i gives me these warnings:
    - warning C4024: 'titulos' : different types for formal and actual parameter 1
    - warning C4047: 'function' : 'char **' differs in levels of indirection from 'char *(*__w64 )[1]'
    "Artificial Intelligence usually beats natural stupidity."

  14. #14
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    I don't know if I'm the only one growing tired of playing 20 questions here.

    If you had stripped the base code down into a minimal compilable snippet you'd have had an answer days ago. It might be worth 20 minutes to try to do so now.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  15. #15
    Registered User IndioDoido's Avatar
    Join Date
    Apr 2007
    Posts
    194
    geatings dave!

    nevermind the last question brewbuck, i've resolved it
    thanks anyway for the help.

    saluts
    "Artificial Intelligence usually beats natural stupidity."

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. NEED HELP READING FILE and PRINTING
    By geoffr0 in forum C Programming
    Replies: 4
    Last Post: 04-16-2009, 05:26 PM
  2. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  3. Replies: 1
    Last Post: 10-27-2006, 01:21 PM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 05:20 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21