[C 언어] scandir의 3번째 인자 warning 좀 잡아주세요.

antz의 이미지

다음과 같이 warning이 납니다.

Quote:
common.c:939: warning: passing arg 3 of `scandir' from incompatible pointer type

다음은 939라인 입니다.
nCount = (int)scandir (pSrcDir, &files, file_select, alphasort);
다음은 3번째 인자 함수 입니다.

int file_select (struct direct *entry) 
{
    if ((strcmp (entry->d_name, ".") == 0)
            || (strcmp (entry->d_name, "..") == 0))
        return FALSE;

    return TRUE;
}

Quote:
int scandir(const char *dir, struct dirent ***namelist, int (*select)(const struct dirent *), int (*compar)(const struct dirent **, const struct dirent **));

에서 "int (*select)(const struct dirent *)" 의 의미를 명확히 모르겠습니다.
인자를 "const struct dirent *" 를 갖고, return값이 int 라는 것 같은데...
"(*select)"의 의미가 뭔지 모르겠습니다.

답변 부탁드립니다.

yielding의 이미지

Quote:

에서 "int (*select)(const struct dirent *)" 의 의미를 명확히 모르겠습니다.
인자를 "const struct dirent *" 를 갖고, return값이 int 라는 것 같은데...

인자를 const struct dirent*를 가지고 int를 리턴하는 함수의 포인터가 scandir의 3번째 인자라는 말입니다

Life rushes on, we are distracted

antz의 이미지

yielding wrote:
Quote:

에서 "int (*select)(const struct dirent *)" 의 의미를 명확히 모르겠습니다.
인자를 "const struct dirent *" 를 갖고, return값이 int 라는 것 같은데...

인자를 const struct dirent*를 가지고 int를 리턴하는 함수의 포인터가 scandir의 3번째 인자라는 말입니다

"(*select)" 가 함수라는 뜻인가요?

잘몰라서,
"int (*select)(const struct dirent *)"
보다는
"int (const struct dirent *)"
라고 생각했습니다.

sodomau의 이미지

return_type (*func_ptr)(parms...)
요렇게 생긴놈들을 함수포인터라고 합니다.
int (*select)(const struct dirent *);
이넘 역시 함수 포인터..
int func(const struct dirent *);
select = func;
select(...);
머 이렇게 쓸 수 있습니다.

함수 이름 자체도 함수 포인터나 마찬가지이니 위의 처음 코드처럼
그냥 쓰셔도 될텐데
아마도 경고가 그

int file_select(const struct dirent *entry)

라고 선언되어야 할 것이

int file_select (struct direct *entry)

요렇게 const가 빠져서.. (direct가 아니고 dirent)

생기는 것 같네요.

mollla wrote:
yielding wrote:
Quote:

에서 "int (*select)(const struct dirent *)" 의 의미를 명확히 모르겠습니다.
인자를 "const struct dirent *" 를 갖고, return값이 int 라는 것 같은데...

인자를 const struct dirent*를 가지고 int를 리턴하는 함수의 포인터가 scandir의 3번째 인자라는 말입니다

"(*select)" 가 함수라는 뜻인가요?

잘몰라서,
"int (*select)(const struct dirent *)"
보다는
"int (const struct dirent *)"
라고 생각했습니다.

antz의 이미지

감사합니다. warning이 사라졌네요. :-)

const가 빠져서 warning이 났던것 같습니다.

sodomau wrote:
요렇게 const가 빠져서.. (direct가 아니고 dirent)

제가 #include <sys/dir.h> 를 해서 에러가 안났던거군요.

dirent를 쓰는게 더 좋은것 같습니다.

Quote:
$ cat /usr/include/sys/dir.h
...
#define direct dirent
...

댓글 달기

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