static으로 사용되는 함수의 프로토타입을 코드 최상단에서 선언하시나요?

superkkt의 이미지

#include "../lib/config_parser.h"
 
#define SCAN_DELAY  2
 
/* db connection handler */
static sql_t sql;
 
static void *non_recursive_backup_thread (void *arg);
 
void
test_func (void)
{
   non_recursive_backup_thread(NULL);
}
 
static void *
non_recursive_backup_thread (void *arg)
{
    return NULL;
}

위 코드에서는 상단에 non_recursive_backup_thread 함수의 프로토타입을 선언하고 있습니다. 이 부분이 빠진다면 test_func에서 non_recursive_backup_thread() 부분에서 undeclared 에러가 발생하겠죠. 뭐 non_recursive_backup_thread 함수가 test_func보다 먼저오게 만든다면 문제 없습니다만 개발하고 기능 추가되다보면 순서 신경쓰는게 힘들죠.

그래서 저는 항상 최상단에서 static 함수들의 프로토타입을 선언했었는데요 이게 함수의 숫자가 늘어나다 보니까 코드 최상단부터 좀 지저분해 보이는 느낌이 들더군요. 그래서 오픈소스 프로젝트들은 어떻게 하는지 뒤져보니 대부분 선언을 안하더라구요.

여러분들은 어떻게 하시나요? 프로토타입 선언 안하고 함수 정의 순서를 신경쓰면서 작업하시나요? 아니면 맘 편하게 프로토타입을 최상단에 선언하시나요?

이것도 어찌보면 개인 취향일수 있을텐데 그냥 궁금해서 글 한번 적어봅니다.

- 추가 -

리턴값이 void가 아닌 함수를 호출할때 리턴값을 무시하는 경우 아래와 같이 (void)를 사용 하시나요? 어떤 라이브러리를 분석하다보니 리턴값을 무시하는 부분에 모두 (void)를 사용한걸 봤는데 그것도 가독성이 별로 좋지는 않더군요. 심지어 memset() 함수마저도 앞에 (void)를 붙여놔서 좀 까칠(?)한것 아닌가 싶기도 하고요. ^^

int
test_func(void)
{
   ...
}
 
...
(void) test_func();
ed.netdiver의 이미지

전 macro는 header에, static fn declaration은 source file include 다음 정도에 해둡니다.
local에서만 쓰는 macro라도 source file에 두다보면 헛갈려서요...
static fn을 먼저 오게 하고, global fn을 file 끝에 추가 하는 사람들도 많은데,
전 반대로 static fn을 file 끝에 trailing하게 둡니다.
생각해보면, cpu가 모자라 걍 늘 두던데다 두지 않으면 혼동되서일뿐 별다른 일은 없지 않나 싶네용^^;
뭐, 한번 더 손이 가긴 합니다만, 그만큼 한번더 caller를 확인한다는 차원에서.
그리고 말씀하신대로 caller, callee위치 신경 안써도 된다는 점때문에 그러고 있는것 같습니다.
static에서 static을 call한달지 하면... 거기다 그게 먼저 작성한 fn이면... 일일이 순서에 맞춰 써줘야
하는데 그게 싫어서용~^^;

근데 open source pjt에선 static fn decl을 안하는거였군요...별로 신경안쓰고 봐서 그런가 몰랐는뎅~^^;
굳이 그런다면 이유는 뭘까요?

--------------------------------------------------------------------------------
\(´∇`)ノ \(´∇`)ノ \(´∇`)ノ \(´∇`)ノ
def ed():neTdiVeR in range(thEeArTh)

--------------------------------------------------------------------------------
\(´∇`)ノ \(´∇`)ノ \(´∇`)ノ \(´∇`)ノ
def ed():neTdiVeR in range(thEeArTh)

superkkt의 이미지

모든 open source project가 다 그런건 아니겠죠. 사실 뒤져봤다고 했는데 딱 두개만 열어봤습니다. ^^ 근데 원래 아이디가 ed.bsd 아니신가요? 아바타는 맞는것 같은데 아이디 바꾸신건가요?

======================
BLOG : http://superkkt.com

======================
BLOG : http://superkkt.com

ed.netdiver의 이미지

그렇군요. 전 예전에 본 pjt에서 static 선언해주는걸로만 봤던것 같아서 아닌가 했습니당^^;
(역시 기억의 조작이..~_~;=33)

흐흐 그리고 ed.bsd맞습니당^^;
ed가 안되서 .bsd를 붙였었습니다만, 잘 알지도 못하는 bsd가 부담도 되고,
간혹 메시지로 bsd에 대해 물어보시는 분들이 계셔서,
순선님께 부탁드려서 변경했습니당^^;

--------------------------------------------------------------------------------
\(´∇`)ノ \(´∇`)ノ \(´∇`)ノ \(´∇`)ノ
def ed():neTdiVeR in range(thEeArTh)

--------------------------------------------------------------------------------
\(´∇`)ノ \(´∇`)ノ \(´∇`)ノ \(´∇`)ノ
def ed():neTdiVeR in range(thEeArTh)

cppig1995의 이미지

그리고 옛날에는 ed군이나 qed, 더 옛날에는 netdiver어쩌구(대소문자섞임)라는 ID를 사용하셨지요;;

Real programmers /* don't */ comment their code.
If it was hard to write, it should be /* hard to */ read.

ed.netdiver의 이미지

헉!@.@; 저같은 미물을 기억하고 계시다니, 눈물이 뒤를 가립니다..ㅠ.ㅠ;
역시 천재적 기억력으로 아무거나 다 기억하시는군요!+.+; cppig1995님 ㅋㅅ^^;
그리고 kldp가 phpbb로 이전하던 때에는 glitch1dix2를 썼었답니다.
geekforum때까지만 해도 손님,익명,나는 겁쟁이 였지요...

근데, 갑자기 얘기가 본 글타래에서 멀어져 전혀 쓸데없는 길로 빠졌군요.
superkkt님 죄송합니다.(-_-)(_._)

--------------------------------------------------------------------------------
\(´∇`)ノ \(´∇`)ノ \(´∇`)ノ \(´∇`)ノ
def ed():neTdiVeR in range(thEeArTh)

--------------------------------------------------------------------------------
\(´∇`)ノ \(´∇`)ノ \(´∇`)ノ \(´∇`)ノ
def ed():neTdiVeR in range(thEeArTh)

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.