Thread: Function types in C

  1. #1
    Registered User
    Join Date
    Dec 2011

    Function types in C

    I'm fairly familiar with C but I cannot seem to figure out the function definitions below.

    Obviously i do not expect you to understand the context, kindly help me to understand the structure / Style.

    This is actually extracted from the Lua source code.

    what type of functions are these ?
    I do not understand the LUA_API keyword. Is this another return type in addition to int? is it some sort of a macro?

    LUA_API int lua_absindex (lua_State *L, int idx) {
    LUA_API void lua_remove (lua_State *L, int idx) {

    I noticed something similar below - this is a function definition extracted from a win32 api tutorial.

    if WinMain is the function name, and int is the return type, then what is WINAPI.

    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,     LPSTR lpCmdLine, int nCmdShow){

    I cannot seem to place this style of coding.

  2. #2
    Registered User
    Join Date
    Nov 2010
    Long Beach, CA
    It is a macro that expands into some special calling conventions or keywords that all Lua API functions should have. Remember, a macro in C is just fancy text substitution. According to this site: Lua: 5.2 source code - luaconf.h, it just expands to the extern keyword. But if they ever want to change the Lua API, it can be done by modifying one place, the LUA_API definition, instead of hundreds of functions.

    WINAPI is the same idea, though probably a bit more complicated.

    This practice is fairly common in libraries, when writing language extensions, etc.

  3. #3
    Registered User
    Join Date
    Dec 2011

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. conflicting types for built-in function
    By BIOS in forum C Programming
    Replies: 5
    Last Post: 09-12-2011, 01:41 PM
  2. Same function different parameter var types
    By rikvdk in forum C Programming
    Replies: 7
    Last Post: 02-07-2011, 06:56 PM
  3. Conflicting Types for function
    By tomeatworld in forum C Programming
    Replies: 1
    Last Post: 12-06-2010, 11:43 AM
  4. Multiple Function Return Types
    By mintsmike in forum C++ Programming
    Replies: 3
    Last Post: 06-23-2009, 12:47 PM
  5. Different types for function parameter - how?
    By ulillillia in forum C Programming
    Replies: 7
    Last Post: 04-21-2007, 05:13 PM

Tags for this Thread