Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DT_REG undeclared (first use in this function) and -std=c99

Tags:

c

I'm writing a C program using Eclipse CDT. I want to init my for loops like this ...

for( int i = 0; i < 5; i++ )

so I added -std=c99 to the gcc command line. This has the side effect of throwing the error: ‘DT_REG’ undeclared (first use in this function) for the line:

if( dir_ent->d_type != DT_REG )

DT_REG is defined in dirent.h (which is included). The code compiles fine without -std=c99 on the gcc command line. What am I missing?

like image 302
J. Andrew Laughlin Avatar asked Feb 25 '11 06:02

J. Andrew Laughlin


1 Answers

What happens with -std=gnu99? It looks like the d_type field is non-standard (see the GNU libc manual page "Directory Entries") and so the enum that represents the directory entry types is disabled in strictly compliant mode. It looks like you need to define _BSD_SOURCE (or _GNU_SOURCE) to get the type values.

like image 86
Jeremiah Willcock Avatar answered Sep 23 '22 06:09

Jeremiah Willcock