The function suddenly returns when it should not

I am working on assigning operating systems to one of my summer classes. The teacher provided an object file that provides functions that mimic the behavior of a disk device driver. Then we need to write a file system API that uses the disk driver in C.

I am working on my file system format function called Format (), which calls a function called DevFormat () from the teachers object file. My function should return 1 if it was able to successfully format the file system and 0 otherwise. DevFormat () returns 1 if it was able to successfully format the disk and 0 otherwise. Here is the code:

int Format()
{
    if (!DevFormat())
    {
        printf("Disk drive wasn't formatted successfully\n");
        return 0;
    }

    <Do some stuff to the file system here>

    printf("File system successfully formatted\n");
    return 1;
}

, Format() , . , : if (!DevFormat()). C, GNU ++ (g++) , , . , Format() , if (!DevFormat()), - ( . .). , , if (0 == DevFormat()). - DevFormat() int .

. , ++ ? - , ?

.

+3
3

, , , if, , :

if (!DevFormat()) {
    printf("Disk drive wasn't formatted successfully\n");
    return 0;
}

if printf, return DevFormat(). C:)

+14

, - ?

0

Try compiling with gcc -fno-exceptionsand see if this has changed anything. (Repeat also the library to be sure.) Also, I am the second @tholomew request to develop on "Format () just abruptly ends up without returning a value.".

0
source

Source: https://habr.com/ru/post/1759019/


All Articles