A simple problem involving prototype function declarations (I hope)

This is a discussion on A simple problem involving prototype function declarations (I hope) within the C Programming forums, part of the General Programming Boards category; The problem is a simple Go-Back-N protocol, the culprit function was provided by the teacher and I am not allowed ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    1

    A simple problem involving prototype function declarations (I hope)

    The problem is a simple Go-Back-N protocol, the culprit function was provided by the teacher and I am not allowed to change it:

    Start line = 516
    Code:
    starttimer(int AorB, float increment)  /* A or B is trying to start timer */
    {
    
     struct event *q;
     struct event *evptr;
    
     if (TRACE>2)
        printf("          START TIMER: starting timer at %f\n",time);
     /* be nice: check to see if timer is already started, if so, then  warn */
    /* for (q=evlist; q!=NULL && q->next!=NULL; q = q->next)  */
       for (q=evlist; q!=NULL ; q = q->next)  
        if ( (q->evtype==TIMER_INTERRUPT  && q->eventity==AorB) ) { 
          printf("Warning: attempt to start a timer that is already started\n");
          return;
          }
     
    /* create future event for when timer goes off */
       evptr = (struct event *)malloc(sizeof(struct event));
       evptr->evtime =  time + increment;
       evptr->evtype =  TIMER_INTERRUPT;
       evptr->eventity = AorB;
       insertevent(evptr);
    }
    Line = 81
    which when I call
    Code:
    starttimer(0, 50.0);
    gives the following errors:
    517 C:\Dev-Cpp\Free\prog2.c conflicting types for 'starttimer'
    517 C:\Dev-Cpp\Free\prog2.c an argument type that has a default promotion can't match an empty parameter name list declaration
    81 C:\Dev-Cpp\Free\prog2.c previous implicit declaration of 'starttimer' was here

    I manged to find this trifecta of errors several places on the internet and the general consensus was that it came from trying to call the function before it declaration (makes sense) with the proposed solution of adding a prototype declaration of that function before the function gets called. So I did this:

    Line 38
    Code:
    starttimer(int AorB, float increment);
    Which seems to fix the original errors but generates me this shiny new error:

    38 C:\Dev-Cpp\Free\prog2.c [Warning] data definition has no type or storage class

    Which I can't find anything to in my scouring of the internet and it basically just has me at a loss. I tried declaring it void, I tried different variable names, passing no variables, moving it around a bit but nothing.

    If anyone could help I would be forever grateful, I'd have your children but alas no uterus.

    Please Help
    Last edited by Aspect; 04-21-2009 at 07:54 PM. Reason: typos

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    At the top of prog2.c, right after your #include directives, add the following line:
    Code:
    void starttimer(int AorB, float increment);
    Optionally, replace void with whatever your return type for that function is supposed to be.

    Reason: You have to know about a function before you can use it.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Also, it is more likely to work "correctly" if you use 50.0f to indicate that your constant is "float" rather than "double".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 12:45 PM
  2. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 09:56 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM

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