Thread: Expression preceding parethenses?

  1. #1
    Registered User
    Join Date
    Oct 2017
    Posts
    33

    Expression preceding parethenses?

    I'm very new to programming and i'm trying to create a delay, but I keep getting the error "expression preceding parentheses of apparent call must have (pointer-to-) function type"

    Code:
    void AI(void){
        unsigned int delay = 1000;
    
    
      if (yR2 > yBall)
      {
       if (yR2 > RACKET ) 
       {
           delay(1000);
        yR2--; 
       }
    
      }
    on the line that has delay(1000); is where i get the error. why is this happening and how can i fix it?

  2. #2
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    950
    There is no delay() function under Linux, but there is a sleep() function.

    If you are on another O/S, then there may or may not be a delay() function. If so, then you need to check the compiler's Standard Library documentation for the correct header file to use.

  3. #3
    Registered User
    Join Date
    Oct 2017
    Posts
    33
    there is a delay function, i've used it before. also, i'm programming a microcontroller.


    what else could be the problem, have i written the code incorrectly?

  4. #4
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    950
    Please show the error message(s) you are receiving.

    Which compiler?

  5. #5
    Registered User
    Join Date
    Oct 2017
    Posts
    33
    i have no idea what compiler it is, this is like homework, so all i have been instructed to do is answer questions using code composer studio. sorry to sound nooby, but i literally started programming 2 days ago

  6. #6
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    950
    Quote Originally Posted by nothing909 View Post
    I'm very new to programming and i'm trying to create a delay, but I keep getting the error "expression preceding parentheses of apparent call must have (pointer-to-) function type"

    Code:
    void AI(void){
        unsigned int delay = 1000;
    
    
      if (yR2 > yBall)
      {
       if (yR2 > RACKET ) 
       {
           delay(1000);
        yR2--; 
       }
    
      }
    on the line that has delay(1000); is where i get the error. why is this happening and how can i fix it?
    Is yR2 a global variable? Is it defined outside of any function?

    Again: Please copy and paste the error message(s) you are receiving into your response, so I can better answer your questions!!!

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,126
    Your specific error message relates to the fact you also have a variable called delay as well.

    If you really have a delay () function, you need to rename your variable.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    950
    Quote Originally Posted by Salem View Post
    Your specific error message relates to the fact you also have a variable called delay as well.

    If you really have a delay () function, you need to rename your variable.
    Guess I am blind! ;^)

    Thanks!

  9. #9
    Registered User
    Join Date
    Oct 2017
    Posts
    33
    The error message is "expression preceding parentheses of apparent call must have (pointer-to-) function type"

    I don't have a delay function, I only have that delay variable. Do I need a delay function?

    And yR2 is a global variable.

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,126
    I guess you could write your own.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  11. #11
    Registered User
    Join Date
    Oct 2017
    Posts
    33
    do i need to write a delay function for the delay to work?
    if so, how do i go about writing it? can you give me an example

  12. #12
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,126
    Inline
    Code:
    int n = 1000;
    volatile int i;
    for ( i = 0 ; i < n ; i++ )
      ; // do nothing
    As a function
    Code:
    void delay ( int n ) {
      volatile int i;
      for ( i = 0 ; i < n ; i++ )
        ; // do nothing
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  13. #13
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by nothing909 View Post
    I'm very new to programming and i'm trying to create a delay, but I keep getting the error "expression preceding parentheses of apparent call must have (pointer-to-) function type"

    Code:
    void AI(void){
        unsigned int delay = 1000;
    
    
      if (yR2 > yBall)
      {
       if (yR2 > RACKET ) 
       {
           delay(1000);
        yR2--; 
       }
    
      }
    on the line that has delay(1000); is where i get the error. why is this happening and how can i fix it?
    if they both got to be true before delay takes place.
    Code:
      if (yR2 > yBall && yR2 > RACKET ) 
       {
           delay(1000);
           yR2--; 
       }

  14. #14
    Registered User
    Join Date
    Oct 2017
    Posts
    33
    Quote Originally Posted by Salem View Post
    Inline
    Code:
    int n = 1000;
    volatile int i;
    for ( i = 0 ; i < n ; i++ )
      ; // do nothing
    As a function
    Code:
    void delay ( int n ) {
      volatile int i;
      for ( i = 0 ; i < n ; i++ )
        ; // do nothing
    }
    i don't understand what you mean, can you relate it to my code?

    do i need to have a function. if so, why. i tried creating a function and it still doesn't resolve the issue.

  15. #15
    Banned
    Join Date
    Aug 2017
    Posts
    861
    that is just a blank loop that just loops for an x amount of time to make a delay occur, give it a try, the larger the number the longer the delay. the need to make his or her code into a function is up to the programmer.
    Last edited by userxbw; 12-10-2017 at 02:34 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Rotation independent of preceding rotations (DirectX)
    By blakeo_x in forum Game Programming
    Replies: 12
    Last Post: 10-03-2012, 05:23 PM
  2. initializer expression list treated as compound expression
    By karthikeyanvisu in forum C Programming
    Replies: 7
    Last Post: 02-26-2011, 05:19 PM
  3. Replies: 2
    Last Post: 11-25-2009, 07:38 AM
  4. preceding zeros in int variables
    By AshFooYoung in forum C Programming
    Replies: 2
    Last Post: 09-23-2001, 02:28 PM
  5. Preceding 0
    By morbuz in forum C++ Programming
    Replies: 2
    Last Post: 09-19-2001, 12:15 PM

Tags for this Thread