Is this valid?

This is a discussion on Is this valid? within the C++ Programming forums, part of the General Programming Boards category; I am working on a code written by someone else. The function I am currently looking at has a segfault ...

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    466

    Is this valid?

    I am working on a code written by someone else. The function I am currently looking at has a segfault in it somewhere, but that's all I have to go on. I wonder if this line could be the problem

    Code:
     modf( (it*dt-prev_output_time)/tout, &N);
    Seems fine, except that N is declared as a double. Will modf cause a segfault if the second parameter is not an int? Or will it just cast the int into a double and store it that way?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,786
    Quote Originally Posted by KBriggs
    Seems fine, except that N is declared as a double. Will modf cause a segfault if the second parameter is not an int? Or will it just cast the int into a double and store it that way?
    Eh, the second parameter of modf is a pointer to double, so there is no problem there.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    The second argument to modf is supposed to be a double*.

  4. #4
    Registered User
    Join Date
    Jun 2009
    Posts
    466
    Oh, so it is haha. Sorry for the wasted question :P

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Minimum valid address value
    By BMintern in forum C Programming
    Replies: 6
    Last Post: 04-12-2008, 08:21 AM
  2. recursion error
    By cchallenged in forum C Programming
    Replies: 2
    Last Post: 12-18-2006, 08:15 AM
  3. Is "public" valid in C?
    By Aries in forum C Programming
    Replies: 7
    Last Post: 06-27-2005, 03:57 AM
  4. Are these valid operators
    By Morgan in forum C Programming
    Replies: 3
    Last Post: 08-12-2003, 11:56 AM
  5. Azbia - a simple RPG game code
    By Unregistered in forum Game Programming
    Replies: 11
    Last Post: 05-03-2002, 06:59 PM

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