size_t probs

This is a discussion on size_t probs within the C++ Programming forums, part of the General Programming Boards category; Hi all, I got a nice 27 warnings from my compiler (VS 2003) when I included the following header file ...

  1. #1
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    359

    size_t probs

    Hi all,

    I got a nice 27 warnings from my compiler (VS 2003) when I included the following header file <sphelper.h> (This is for the speech 5.1 api). I have included it if anyone wants to have a look at it.

    Now my program compiles fine, but I would like to get rid of these warnings. Now it says:

    sphelper.h(334) : warning C4267: 'initializing' : conversion from 'size_t' to 'ULONG', possible loss of data.

    I have looked within the stdlib.h file, and size_t is declared as an unsigned int. Now shall i change every definition of size_t within every header file to ULONG, or should I start changing this header file? What is best to do?

    Thanks.
    Attached Files Attached Files
    Be a leader and not a follower.

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Warnings aren't always important. In this case, I don't think there's any need for concern. The issue I believe is that an 'int' can either be 16-bit or 32-bit, depending on your processor. Basically every processer you can find these days is 32-bit. A ULONG is always 32-bits. Thus, you get a warning because theoretically your code may produce undefined behavior on some systems. However, it's not something you should worry about. Just ignore the warnings.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  3. #3
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    359
    :-) Ok, but I just like a nice clean build with no errors and no warnings.... Doesn't every programmer? Ok, thanks for the help.
    Be a leader and not a follower.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,673
    > The issue I believe is that an 'int' can either be 16-bit or 32-bit,
    Don't forget 64 bit.
    The warning is telling you that if int were to become 64 bit, then you may have loss of data, even if that is currently impossible in your current implementation.

    > I got a nice 27 warnings from my compiler (VS 2003)
    Send a bug report to MS to ask them to fix the implementation.

    If you can't include any header file at the maximum warning level without it generating internal warnings, then it is broken.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2 simple C++ probs
    By alikoolg in forum C++ Programming
    Replies: 4
    Last Post: 03-18-2009, 09:02 PM
  2. Replies: 2
    Last Post: 11-04-2007, 11:55 AM
  3. WM_TIMER probs (FPS Calculations)
    By C+noob in forum C++ Programming
    Replies: 0
    Last Post: 10-02-2005, 02:39 AM
  4. Several Probs
    By gamer4life687 in forum C++ Programming
    Replies: 4
    Last Post: 12-25-2002, 06:40 PM
  5. magic sq probs
    By scuba22 in forum C++ Programming
    Replies: 2
    Last Post: 11-18-2002, 08:40 AM

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