Liste des Groupes | Revenir à l c |
Am 07.06.2025 um 20:43 schrieb wij:
The error from opendir(..):
EACCES Permission denied.
EBADF fd is not a valid file descriptor opened for reading.
EMFILE The per-process limit on the number of open file descriptors has
been reached.
ENFILE The system-wide limit on the total number of open files has been
reached.
ENOENT Directory does not exist, or name is an empty string.
ENOMEM Insufficient memory to complete the operation.
ENOTDIR name is not a directory.
...
With C++ that's all encapsulated in filesystem_error which is derived
from system_error. But you can omit permission denied errors with
directory_options::skip_permission_denied. That makes sense mostly
with recursive_directory_iterator.
If you want to to that in C you've
at least ten times the code.
I think your 'less work' was from simplication or idealization, lots are
simplified and idealized.
No, show me your C code to iterate through a directory and I show you
the same code with up to a fifth of C++-code. When you iterate
recur-sively that's a tenth of the code.
If you can handle errors that way, C can also do it in much simpler way..
Absolutely not.
The basic problem of throwing error is losing error context, it is similar
to set a global errno (or object) and cause the program to stack unwind..
The context doesn't matter. A bad_alloc doesn't need context, a
system_error also not. And that's most of the exceptions the C++
runtime throws (some are derived from system_error).
C++ has many artificial fancy things and encourages such programming style.
Good or bad? Both, but I would say mostly bad.
C is bad, because you've to do simple things over and over with multiple
times the code because there are no language-facilities to abstract your
coding.
Les messages affichés proviennent d'usenet.