Thread: gcc warning: implicit declaration of function `f2c_generate_note01'

  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    2

    Question gcc warning: implicit declaration of function `f2c_generate_note01'

    I have a warning from gcc compiler, which I don't know the reason of it.
    Can anyone help? The warning is:
    - warning: implicit declaration of function 'f2c_generate_note'

    The code is as below:

    struct elf_note
    {
    int namesz;
    int descsz;
    int type;
    char name[8];
    };

    int f2c_dump_core(const char *name, struct crashdump_foc_t *foc)
    {
    int file;
    struct elf_note *note01;

    if ((file = open(name, O_WRONLY | O_CREAT, 0777)) == NULL)
    {
    printf("can not open core file: %s\n", strerror(errno));
    return -1;
    }

    f2c_generate_note01(&note01);

    if(lseek(file, 116, SEEK_SET) == NULL)
    {
    printf("seek note01 failed: %s.", strerror(errno));
    return -1;
    }

    if(write(file, note01, sizeof(struct elf_note)) == NULL)
    {
    printf("write note01 failed: %s.", strerror(errno));
    return -1;
    }

    close(file);
    }

    int f2c_generate_note01(struct elf_note *note)
    {
    note->descsz = sizeof(struct elf_prpsinfo);
    note->type = 3;
    strcpy(note->name,"CORE");
    note->namesz = sizeof(note->name);
    }

    The role of subfunction "f2c_generate_note01" is to fill the struct elf_note.

    And the role of function "f2c_dump_core" is to write the elf_note into a file.

  2. #2
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    When posting code, you need to use code tags. See here for what I am referring to. Here is your code with some indentation (which is preserved by using code tags):

    Code:
    struct elf_note {
        int namesz;
        int descsz;
        int type;
        char name[8];
    };
    
    int f2c_dump_core(const char *name, struct crashdump_foc_t *foc)
    {
        int file;
        struct elf_note *note01;
    
        if ((file = open(name, O_WRONLY | O_CREAT, 0777)) == NULL) {
            printf("can not open core file: %s\n", strerror(errno));
            return -1;
        }
    
     f2c_generate_note01(&note01);
    
        if (lseek(file, 116, SEEK_SET) == NULL) {
            printf("seek note01 failed: %s.", strerror(errno));
            return -1;
        }
    
        if (write(file, note01, sizeof(struct elf_note)) == NULL) {
            printf("write note01 failed: %s.", strerror(errno));
            return -1;
        }
    
        close(file);
    }
    
    int f2c_generate_note01(struct elf_note *note)
    {
        note->descsz = sizeof(struct elf_prpsinfo);
        note->type = 3;
        strcpy(note->name, "CORE");
        note->namesz = sizeof(note->name);
    }
    As for the warning, try using some function prototypes. This ought to fix your trouble.
    Last edited by kermit; 08-23-2010 at 08:54 PM.

  3. #3
    Registered User
    Join Date
    Aug 2010
    Posts
    2
    thank you for your correction. This is my first time post here, so I don't familiar with the rule. Next time I will pay attention to this problem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling Libraries in C
    By TheOriginalGame in forum C Programming
    Replies: 3
    Last Post: 08-15-2010, 11:19 AM
  2. gcc warning: implicit declaration of function
    By anatoly in forum C Programming
    Replies: 4
    Last Post: 05-02-2010, 04:32 PM
  3. Replies: 2
    Last Post: 09-16-2009, 06:00 AM
  4. File Server Help
    By lautarox in forum C Programming
    Replies: 146
    Last Post: 09-24-2008, 06:32 PM
  5. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM

Tags for this Thread