Including <string.h> fails if <cstring> included

O

Old Wolf

On one particular compiler, this program fails to compile because
memset is an undeclared symbol (it's in namespace std but not in
the global namespace):

#include <cstring>
#include <string.h>

int main()
{
char a[10];
memset(&a, '\0', 10);
return 0;
}

But if the first line is removed then the program compiles.
Apparently what is happening is that the include guards activated
by <cstring> mean that the second include is ignored.

Should this be considered a compiler bug?
 
J

Jim Langston

Old Wolf said:
On one particular compiler, this program fails to compile because
memset is an undeclared symbol (it's in namespace std but not in
the global namespace):

#include <cstring>
#include <string.h>

int main()
{
char a[10];
memset(&a, '\0', 10);
return 0;
}

But if the first line is removed then the program compiles.
Apparently what is happening is that the include guards activated
by <cstring> mean that the second include is ignored.

Should this be considered a compiler bug?

I wouldn't think so. I think it would be more a programmer error to include
both Cxxxx and xxxx.h
 
D

dudordoo123456

Old said:
On one particular compiler, this program fails to compile because
memset is an undeclared symbol (it's in namespace std but not in
the global namespace):

#include <cstring>
#include <string.h>

int main()
{
char a[10];
memset(&a, '\0', 10);
return 0;
}

But if the first line is removed then the program compiles.
Apparently what is happening is that the include guards activated
by <cstring> mean that the second include is ignored.

Should this be considered a compiler bug?

cstring includes and will call string.h if syntax or compile errors
popped up
 
M

Moli King

Old Wolf ha escrito:
On one particular compiler, this program fails to compile because
memset is an undeclared symbol (it's in namespace std but not in
the global namespace):

#include <cstring>
#include <string.h>

int main()
{
char a[10];
memset(&a, '\0', 10);
return 0;
}

But if the first line is removed then the program compiles.
Apparently what is happening is that the include guards activated
by <cstring> mean that the second include is ignored.

Should this be considered a compiler bug?

It's a commpiler bug, you shold read document ?

Davio C. Doug
 
M

Moli King

Old Wolf ha escrito:
On one particular compiler, this program fails to compile because
memset is an undeclared symbol (it's in namespace std but not in
the global namespace):

#include <cstring>
#include <string.h>

int main()
{
char a[10];
memset(&a, '\0', 10);
return 0;
}

But if the first line is removed then the program compiles.
Apparently what is happening is that the include guards activated
by <cstring> mean that the second include is ignored.

Should this be considered a compiler bug?

It's a commpiler bug, you shold read document ?

Davio C. Doug
 
D

dudordoo123456

Moli said:
Old Wolf ha escrito:
On one particular compiler, this program fails to compile because
memset is an undeclared symbol (it's in namespace std but not in
the global namespace):

#include <cstring>
#include <string.h>

int main()
{
char a[10];
memset(&a, '\0', 10);
return 0;
}

But if the first line is removed then the program compiles.
Apparently what is happening is that the include guards activated
by <cstring> mean that the second include is ignored.

Should this be considered a compiler bug?

It's a commpiler bug, you shold read document ?

Davio C. Doug

that's posibly a good "guess" but at least good compiler doesnot give
priority to which header shoud be read first, header knows which to
include and to exclude
 
I

In a little while

Jim said:
Old Wolf said:
On one particular compiler, this program fails to compile because
memset is an undeclared symbol (it's in namespace std but not in
the global namespace):

#include <cstring>
#include <string.h>

int main()
{
char a[10];
memset(&a, '\0', 10);
return 0;
}

But if the first line is removed then the program compiles.
Apparently what is happening is that the include guards activated
by <cstring> mean that the second include is ignored.

Should this be considered a compiler bug?

I wouldn't think so. I think it would be more a programmer error to include
both Cxxxx and xxxx.h


I find that including both files is a baad haabit of coders. but why
compiler error ?
it must be a compiler bug instead :p
 
K

Kai-Uwe Bux

Jim said:
Old Wolf said:
On one particular compiler, this program fails to compile because
memset is an undeclared symbol (it's in namespace std but not in
the global namespace):

#include <cstring>
#include <string.h>

int main()
{
char a[10];
memset(&a, '\0', 10);
return 0;
}

But if the first line is removed then the program compiles.
Apparently what is happening is that the include guards activated
by <cstring> mean that the second include is ignored.

Should this be considered a compiler bug?

I wouldn't think so.

I would: where in the standard do you find the permission that one header
may hide the contents of another header?
I think it would be more a programmer error to
include both Cxxxx and xxxx.h

True but irrelevant for assesing whether the compiler is compliant.


Best

Kai-Uwe Bux
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,190
Latest member
Martindap

Latest Threads

Top