0

I am new to the programming world, and this is my first post, so excuse my verbosity.

I have started learning C recently. I found something very interesting in C today and was wondering if someone can guide me to correct direction or help me to understand that why below code works fine. I have done few search but unable to find right reason or rationale that why this is happening:

For example: I have written a function with any number of parameter in the argument call to my function call test_hello_world which don't even have an argument my program throws no error apart form the "implicit declaration of function warning"

Sample code

—— Code—-

#include<stdio.h>

int main()
{
    test_hello_world(1, 2, 3, 4, 4, 5, 5);
    return 0;
}

int test_hello_world(){
    printf("Hello World! debug purpose \n");
    return 0;
} 
StoryTeller - Unslander Monica
  • 165,132
  • 21
  • 377
  • 458
AA_Float
  • 59
  • 4
  • 1
    C != C++. Tag only with the language that you're using, unless both are actually relevant. – tambre Nov 20 '17 at 06:01
  • 1
    Always compile with **compiler warnings enabled** (e.g. `-Wall -Wextra` minimum on `gcc` or `/W3` for `cl.exe` (VS)). Do not accept code until it compiles without warning. And specify whether you are simply compiling to object or attempting to create an executable. `"warning: implicit declaration of function ‘test_hello_world’"` – David C. Rankin Nov 20 '17 at 06:04
  • Compiling for C11 (the current standard) or C99 (the old standard) would trigger all sorts of compilation warnings. Only compiling for C90 (the archaic standard) permits that code to compile without warnings. You're learning C in the 21st Century; learn to code in 21st Century C. What you show is not 21st Century C. – Jonathan Leffler Nov 20 '17 at 06:15
  • @JonathanLeffler I compiled this with `-std=c11 -Wall -Wextra -pedantic` but got no extra warnings except *implicit declaration* – klutt Nov 20 '17 at 07:35
  • @klutt: OK; 'all sorts' means 'implicit declaration'. Were it my default set of compilation options, there'd be complaints about non-prototype definitions too, and they'd be errors (`-Werror -Wmissing-prototypes -Wstrict-prototypes`, and maybe a few extras). The space before the newline in the format string would earn demerits from me reviewing it, but I don't know of a compiler option to trigger warnings about it. – Jonathan Leffler Nov 20 '17 at 07:38
  • @JonathanLeffler Ah, ok. Your comment implied that *this specific piece of code* would trigger more warnings with more flags. – klutt Nov 20 '17 at 07:39
  • Yeah; I over-stated my case. I still think that the fact it compiled indicates faulty use of modern compilers, or use of archaic compilers (or, more precisely, modern compilers that only support archaic versions of standard C, at least by default). But that’s a mouthful. – Jonathan Leffler Nov 20 '17 at 07:42

0 Answers0