gcc 가 미쳤어요..혼란스럽습니다.

yijane의 이미지

a.c 에서 err_quit이라는 함수가 구현되어있고.
b.c 에서 err_quit이라는 함수를 쓰려고 합니다.

----------------------------------------
a.c
#include
void err_quit(char *s)
{
printf("%s", s);
}

----------------------------------------
b.c
#include
int main(void)
{
err_quit("test");
}
----------------------------------------
gcc -o test a.c b.c 하니까 컴파일이 되고
b.c에서 그냥 쓰려고 하니 사용이 되네요?!?
이 무슨해괴망층한 일인가요 원래 되는건가요?;

익명 사용자의 이미지

cpp면 몰라도 c면 정상동작 맞아요

라스코니의 이미지

gcc -o test b.c a.c 이렇게 해보세요.

yeonpil_net의 이미지

^^

리턴값이 있더라도 파라미터도 정확히 일치 하지 않아도 되지 않나요? 포트란이 함수를 호출하는 것을 생각하면 그렇습니다. 리턴형이 일치해야 하는지도 체크하지 않고, 리턴될 변수의 값이 저장될 공간이 필요하다! 라는 의미의 변수 선언만 있으면 되니.

그 난잡함을 해결하기 위해 90에선 모듈이나 인터페이스가 도입되었지만.. C에선 아직 그 것을 완전히 확실히 할 방법이 없는 것으로 아는데..

!23456---1----+----2----+----3----+----4----+----5----+----6----+----7-2--+----8
"배웠다"는 "할 수 있다"의 동의어가 아니다.

yeonpil_net의 이미지

a.c

void err_quit(char *s, int i)
{
i = 1;
printf("%s \n", s);
printf("%d \n", i);
}

----------------------------------------

b.c

int main(void)
{
err_quit("test");
}
----------------------------------------

컴파일은 될 겁니다. 수행도 될 겁니다.
+++++++++++++++++++++++++++++++++++++++++++++
a.c

void err_quit(char *s, int i)
{
i = 1;
printf("%s \n", s);
printf("%d \n", i);
}
---------------------------------
b.c

extern err_quit(char *);

int main(void)
{
err_quit("test");
}
----------------------------------------
이렇게도..
b.c 의 저 외부 함수 선언이 a.c에 정의된 함수와 일치한다는 보장은 받을 수 없습니다. 그건 프로그래머가 확실하게 해야 할 몫입니다.
그게 아마 C가 추구하는 생각 일겁니다. 무심코 인클루드하는 헤더파일에도 구라가 있을 수 있습니다.

!23456---1----+----2----+----3----+----4----+----5----+----6----+----7-2--+----8
"배웠다"는 "할 수 있다"의 동의어가 아니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.