[완료]함수포인터에 대한 질문입니다....

tommybee의 이미지

안녕하세요
그냥 데이터구조 공부하다가 에러가 생겨서 이렇게 질문 드립니다

다름이 아니라 제가 만든 것은 compare라는 함수 포인터를 활용하는 부분인데요 소스는 다음과 같이 하였습니다

t_linkedlist.h 파일이 아래와 같습니다.
typedef struct node
{
void* dataPtr;
struct node* link;
} NODE;

typedef struct
{
int count;
NODE* pos;
NODE* head;
NODE* rear;
int (*compare)(void*, void*);
} LIST;

LIST* createList (int (*compare)(void* argu1, void* argu2));

t_linkedlist.c 파일을 다음과 같이 작성하였습니다.
#include "t_linkedlist.h"

LIST* createList
(int (*comapre)(void* argu1, void* argu2))
{
LIST* __list;

__list = (LIST*)malloc(sizeof(LIST));

if(__list)
{
__list->head = NULL;
__list->pos = NULL;
__list->rear = NULL;
__list->count = 0;
__list->compare = compare;
} //end if

return __list;
}
그리고 linkedlist_main.c를 만들고 다음과 같이 작성 하였습니다

int cmpYear (void* pYear1, void* pYear2);

int main(int argc, int** argv)
{
LIST* list;

list = createList(cmpYear);
if(!list)
printf("\aCannot create list\n"),
exit(100);
return 0;
}

int cmpYear(void* pYear1, void* pYear2)
{
int result;
short year1;
short year2;

year1 = ((PICTURE*)pYear1)->year;
year2 = ((PICTURE*)pYear2)->year;

if(year1 result = -1;
else if( year1 > year2)
return 1;
else
result = 0;

return result;
}
에러메시지는 error C2065: 'compare' : undeclared identifier이구요
warning은 warning C4047: '=' : 'int (__cdecl *)(void *,void *)' differs in levels of indirection from 'int '입니다
물론 compare함수를 정의하지는 않았습니다만 나중에 메인에서 원래 int cmpYear (void* pYear1, void* pYear2);로 대체 할려고 했는 데요
이런 구문은 안되는 건가요? 고수님들의 조언 부탁드립니다
컴파일은 visual c++6.0에서 했습니다.

cppig1995의 이미지

1) C2065: createList 함수의 머리에 compare가 comapre로 적혀, 오타가 있습니다.
2) C4047: 몇 행에서 경고가 났는지 알려주시기 바랍니다.
3) pYear1이 정수 값 1987을 캐스팅한 것인 상황에서 year1 = ((PICTURE*)pYear1)->year;이라는 표현은 매우 위험하게 보여집니다.

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

tommybee의 이미지

오타군요.......
오타...
하지만 앞으로는 더 잘할 수 있을것 같습니다..

댓글 달기

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