#hgdassdfas

31 messages · Page 1 of 1 (latest)

hybrid coyoteBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

surreal blade
#

errno.h is a header file in the standard library of the C programming language. It defines macros for reporting and retrieving error conditions using the symbol errno (short for "error number").errno acts like an integer variable. A value (the error number) is stored in errno by certain library functions when they detect errors. At program start...

hybrid coyoteBOT
#

@cold ice Has your question been resolved? If so, run !solved :)

faint gust
#

Basically, the implementation can do what they want

#

;asm -E

#include <errno.h>

errno
hoary yewBOT
#
Assembly Output Pt. 1
# 0 "/app/example.c"
# 1 "/app//"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 0 "<command-line>" 2
# 1 "/app/example.c"
# 1 "/usr/include/errno.h" 1 3 4
# 25 "/usr/include/errno.h" 3 4
# 1 "/usr/include/features.h" 1 3 4
# 461 "/usr/include/features.h" 3 4
# 1 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 1 3 4
# 452 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 3 4
# 1 "/usr/include/x86_64-linux-gnu/bits/wordsize.h" 1 3 4
# 453 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 2 3 4
# 1 "/usr/include/x86_64-linux-gnu/bits/long-double.h" 1 3 4
# 454 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 2 3 4
# 462 "/usr/include/features.h" 2 3 4
# 485 "/usr/include/features.h" 3 4
# 1 "/usr/include/x86_64-linux-gnu/gnu/stubs.h" 1 3 4
# 10 "/usr/include/x86_64-linux-gnu/gnu/stubs.h" 3 4
# 1 "/usr/include/x86_64-linux-gnu/gnu/stubs-64.h" 1 3 4
# 11 "/usr/include/x86_64-linux-gnu/gnu/stubs.h" 2 3 4
# 486 "/usr/include/features.h" 2 3 4
# 26 "/usr/include/errno.h" 2 3 4


Assembly Output Pt. 2
# 1 "/usr/include/x86_64-linux-gnu/bits/errno.h" 1 3 4
# 26 "/usr/include/x86_64-linux-gnu/bits/errno.h" 3 4
# 1 "/usr/include/linux/errno.h" 1 3 4
# 1 "/usr/include/x86_64-linux-gnu/asm/errno.h" 1 3 4
# 1 "/usr/include/asm-generic/errno.h" 1 3 4

# 1 "/usr/include/asm-generic/errno-base.h" 1 3 4
# 6 "/usr/include/asm-generic/errno.h" 2 3 4
# 2 "/usr/include/x86_64-linux-gnu/asm/errno.h" 2 3 4
# 2 "/usr/include/linux/errno.h" 2 3 4
# 27 "/usr/include/x86_64-linux-gnu/bits/errno.h" 2 3 4
# 29 "/usr/include/errno.h" 2 3 4

# 37 "/usr/include/errno.h" 3 4
extern int *__errno_location (void) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__const__));
# 52 "/usr/include/errno.h" 3 4

# 2 "/app/example.c" 2

(*__errno_location ())

faint gust
#

See how errno expands to (*__errno_location ())

#

Here errno is a macro that expands to a function call, rather than just being a variable

#

Not something you have to worry about though. Just an implementation detail.

#

You can print the value of errno

#

;compile -lm

#include <math.h>
#include <stdio.h>
#include <errno.h>

int main() {
    printf("%d\n", errno);
    double x = log(-1);
    printf("%d\n", errno);
}
hoary yewBOT
#
Program Output
0
33
faint gust
#

errno.h isn't a library

#

It's a header file that contains the definition of errno, and is part of the C standard library

#

#include <errno.h> provides the definition of errno that is needed to read the errno set by other standard library functions

#

Correct

#

Under the hood it will #include <errno.h> though

#

Because #include <errno.h> is how you access errno

faint gust
#

Maybe, maybe not

#

Maybe internally in the .c files that contain definitions for stdio.h functions

#

If you'd like to learn more, you can read standard library code

#

here

#

And you'll notice immediately on line 18, #include <errno.h>

#

It's not declared internally in stdio.h

#

It's declared in errno.h, but in some implementations stdio.h could #include errno.h or likely the .c files that contain definitions for stdio.h functions will #include errno.h

hybrid coyoteBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

hybrid coyoteBOT
#

<@undefined>

Please Do Not Delete Posts!

Please don't delete forum posts. They can be helpful to refer to later and other members can learn from them. In the future you can use !solved to close a post and mark a post as solved.