useless function argument

This is a discussion on useless function argument within the C++ Programming forums, part of the General Programming Boards category; I can see why this code is harmless, but it seems so silly I don't know why g++ doesn't warn ...

  1. #1
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    902

    useless function argument

    I can see why this code is harmless, but it seems so silly I don't know why g++ doesn't warn with -Wall.
    Code:
    #include <ctime>
    void func(std::time_t)
    {
         //do whatever
    }
    
    int main()
    {
         func( std::time(0) );
    }
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,448
    Sometimes, a parameter is intentionally ignored. What surprises me is that when you give the parameter a name, the MinGW port g++ 3.4.5 does not emit a warning concerning an unused variable despite the -Wall option.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    The larch
    Join Date
    May 2006
    Posts
    3,573
    It warns with -Wall and -Wextra, though.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    -Wunused-argument is separate from -Wunused-variable because it's more likely to ignore an argument than a local variable. By the same notion, -Wunused-variable is part of -Wall, while -Wunused-argument is in -Wextra.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    902
    I see.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 03:33 AM
  4. Replies: 8
    Last Post: 03-10-2008, 11:57 AM
  5. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM

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