Thread: problems with too many warning messages?

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    202

    problems with too many warning messages?

    is there any possible problems that can arise from too many error messages? On my current project I am getting 7 warnings 5 from unused parameters and 2 from possible use before declaration. Are there any problems that this can cause?

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Usually they are there for a reason......

    Its hard to tell what may happen without seeing anything specific...

    Post some code....

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > 5 from unused parameters
    This is just clutter - it won't do any harm, but it should be tidied up at some point

    > 2 from possible use before declaration
    You mean use before initialisation?
    This is potentially serious
    Code:
    int *foo;
    if ( n > 0 ) {
        foo = malloc( n * sizeof(int) );
    }
    for ( i = 0 ; i < n ; i++ ) {
        foo[i] = 0;
    }
    Now you and I know that this is OK, because foo is only allocated and used if n > 0. However, the compiler might not be able to tell this.

    A more complex example might leave you with a possible path through the code to where a variable might be used before being initialised, and at that point, your code is broken.

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    202
    How should I "tidy up" the unused parameters?
    Yes i meant before initation. This is where Im getting those errors:
    BOOL CALLBACK PointSelProc (HWND hDlg, UINT message,
    WPARAM wParam, LPARAM lParam)
    {

    int xpoint, ypoint;
    switch (message)
    {
    case WM_INITDIALOG :
    return TRUE ;


    case WM_COMMAND :
    switch (LOWORD (wParam))
    {
    case IDOK :
    hdc=GetDC(hwnd) ;
    SelectObject (hdc, GetStockObject (BLACK_BRUSH)) ;
    Ellipse(hdc, xpoint - 5, ypoint + 5, xpoint + 5, ypoint - 5);
    ReleaseDC(hwnd, hdc) ;
    return TRUE ;

    case IDCANCEL :
    EndDialog (hDlg, 0) ;
    return TRUE ;

    }
    break ;
    }
    return FALSE ;
    }

    The variables xpoint and ypoint are edit boxes in the dialog box. The user changes the values presses OK and the computer will draw a elipse to signalfy a point (its a graphing prog).
    Should I be worried or is it just "clutter"?

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    There's not a lot you can do about the unused parameters - I take it that it's part of the standard interface.

    Something like
    lParam = lParam;
    Sometimes works at keeping the compiler happy. You may find you use more of them as the code expands.

    > int xpoint, ypoint;
    But how are these initialised?

    You've mentioned a dialog box, but even if that's handled inside this function, it's going to be a different message (and hence a different invocation of this function). If this is so, then xpoint will contain fresh random garbage each time the function is called.

    If you want these vars to remember the dialog values in one message, and be used in the next message which draws the ellipse, then you need to make these static, like
    static int xpoint, ypoint;

  6. #6
    Registered User
    Join Date
    Nov 2001
    Posts
    202
    That is the dialog box procedure. Should they still be static? And your right with the parameters they are just part of the Windows and Dialog boxes standard procedures.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > That is the dialog box procedure
    No idea - repost more code on the windows board - I can't help with the details....

  8. #8
    Registered User
    Join Date
    Nov 2001
    Posts
    202
    Ok...I'll post a thread on the windows board call "Warning messages"
    Just give me a couple of sec to post post it

  9. #9
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    i'd imagine any programmer defined functions can be bulletproofed against these kinds of warnings... [i used to leave the warnings be, but in the end it's better practice...] and i would also imagine that the compiler's libraries were designed such that no warnings [let alone errors] would occur with correct linkage to all said libraries...
    hasafraggin shizigishin oppashigger...

  10. #10
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    most compilers support pragmas of this sort since its part of the standard though i don't know what the syntax and use rules are... check the compiler doc's ir something if these don't work.

    #pragma warning(disable:errornumberhere)

    // Code Segment...

    #pragma warning(default:errornumberhere)
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Malloc access violation
    By JOCAAN in forum C Programming
    Replies: 7
    Last Post: 11-30-2008, 04:47 AM
  2. GradeInfo
    By kirksson in forum C Programming
    Replies: 23
    Last Post: 07-16-2008, 03:27 PM
  3. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  4. DLL compiling question
    By Noose in forum Windows Programming
    Replies: 2
    Last Post: 12-16-2004, 07:16 AM
  5. Try out my new game :) !
    By Stan100 in forum Game Programming
    Replies: 10
    Last Post: 06-05-2003, 08:10 AM