Thread: stdarg, checking for # of entered arguments

  1. #1
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802

    stdarg, checking for # of entered arguments

    Code:
    void CMatrix::SetRow(unsigned short iRowNum, ...)
    {
    	if (m_pdMatrixData == NULL) return;
    	// Error Checking;
    
    	va_list vaList;
    	// Variable length argument lists... defined in stdarg.h;
    
    	va_start(vaList, iRowNum);
    
    	for (int i = 0; i < m_iDimension[0]; i++)
    	{
    
    		m_pdMatrixData[iRowNum][i] = va_arg(vaList, double);
    	}
    }
    How would I go about checking that the number of arguments entered is less than m_iDimension[0]? I searched on MSDN, and I tried something like sizeof(vaList)/sizeof(double) < m_iDimension[0] but that didn't seem to work.
    Any help would be much appreciated.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > How would I go about checking that the number of arguments entered is less than m_iDimension[0]?
    You can't - at least not in any portable way

    Consider these two stdarg type functions
    1. printf
    The number of arguments expected (not enforced) is determined by the number of % conversions in the control string. What happens when you pass more/less than the expected number is implementation defined (but its rarely good)

    2. execl
    The of program arguments is terminated by a NULL pointer.

    In both cases, the called function knows how to work out the number of expected parameters, even if the programmer got it wrong.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking function arguments
    By melkor445 in forum C Programming
    Replies: 16
    Last Post: 12-11-2008, 01:15 PM
  2. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  3. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  4. Problems about gcc installation
    By kevin_cat in forum Linux Programming
    Replies: 4
    Last Post: 08-09-2005, 09:05 AM
  5. Need HELP with Program
    By Jeff in forum C Programming
    Replies: 25
    Last Post: 09-23-2004, 08:03 PM