Thread: General question.

  1. #1
    Registered User
    Join Date
    Apr 2020
    Posts
    62

    Arrow General question.

    When you declare a function in a program with structs, does it matter where the argument is placed or it does not matter?

    Here is an example:

    Code:
    typedef struct
    {
    }
    typedef struct
    {
    }
    int newIncident();

  2. #2
    Registered User
    Join Date
    May 2012
    Posts
    502
    Quote Originally Posted by TheGreekMan2000 View Post
    When you declare a function in a program with structs, does it matter where the argument is placed or it does not matter?

    Here is an example:

    Code:
    typedef struct
    {
    }
    typedef struct
    {
    }
    int newIncident();

    If you typedef your structs, the typedef has to come before any
    prototypes which reference that typedef. However in this case,
    the prototype newIncident() doesn't reference any structs,
    so it can appear anywhere.

    However it conventional to lay out a header by declaring the
    structs and other types first, then declaring the functions.
    I'm the author of MiniBasic: How to write a script interpreter and Basic Algorithms
    Visit my website for lots of associated C programming resources.
    https://github.com/MalcolmMcLean


  3. #3
    Registered User
    Join Date
    Apr 2020
    Posts
    62
    If the function needs a struct that references for example the two previous structs what should I do? You have just played with my curiosity. Here is an example of what I mean:

    Code:
    typedef struct
    {
    
    }a;
    typedef struct
    {
    
    }b;
    typedef struct
    {
    a reported;
    b coordinates;
    
    }
    
    int newIncident();

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. general question
    By ingeniousreader in forum C Programming
    Replies: 4
    Last Post: 05-21-2012, 09:59 AM
  2. General API Question
    By legion050 in forum C Programming
    Replies: 2
    Last Post: 11-23-2010, 06:00 AM
  3. General question
    By saudi-vip in forum C Programming
    Replies: 11
    Last Post: 10-10-2008, 04:46 PM
  4. A general question
    By vampire in forum C Programming
    Replies: 7
    Last Post: 11-06-2005, 09:53 PM
  5. General Question
    By GSLR in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 05-02-2002, 12:15 PM

Tags for this Thread