Where is this crypt function coming from? (C++)

  • Context: C/C++ 
  • Thread starter Thread starter Grep
  • Start date Start date
  • Tags Tags
    Function
Click For Summary

Discussion Overview

The discussion revolves around the unexpected behavior of a 'crypt' function in C++ when trying to instantiate a class named 'crypt'. Participants explore the origins of this function and its implications on code compilation, particularly in the context of different versions of the g++ compiler and included headers.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant expresses confusion about the source of the 'crypt' function, noting that it appears without including any C headers or the standard namespace.
  • Another participant suggests that including may inadvertently pull in , leading to the declaration of 'crypt', and questions the ANSI compliance of g++.
  • A later reply confirms that both and include the 'crypt' symbol, while removing all headers resolves the issue.
  • One participant mentions testing with gcc version 4.6, where the issue does not occur, implying it may be a bug in earlier versions like 4.4.
  • Several participants humorously suggest searching for the 'crypt' function in the /usr/include directory using grep, indicating a light-hearted tone amidst the technical discussion.

Areas of Agreement / Disagreement

Participants generally agree that the 'crypt' function is unexpectedly included through certain headers, but there is no consensus on the exact cause or whether it constitutes a bug in specific compiler versions.

Contextual Notes

Limitations include the lack of clarity on which specific headers are causing the inclusion of 'crypt' and the implications of different compiler versions on this behavior.

Grep
Messages
298
Reaction score
3
Helping matumich26 in another thread, I'm running into something puzzling and hoped someone might know what's going on. I must be missing something...

Though 'crypt' is probably a bad name for the class, and the problem is easily avoided by capitalizing the first latter, I still don't know where this crypt function is coming from.

I get this when he tries to instantiate his 'crypt' class:
crypt.cpp:109: warning: statement is a reference, not call, to function ‘crypt’

Now, I've removed the #include <stdlib.h> just in case it's being pulled in from there. Nope, still complains. No C headers included at all.

I took out the 'using namespace std;' and used 'using std::string;' and so on so I don't have the whole std namespace pulled in. Nope, it's not in the std namespace, I guess. Nor can I find a reference to one in documentation.

So I have no C header files included, nor the std namespace. Why the heck is 'crypt' still declared? From the man page for crypt(3) - if that's the culprit - I should need to include unistd.h. It's not.

Anyone know where the heck it's coming from (on a Linux system, BTW)? It's kind of bothering me. :frown:
 
Technology news on Phys.org
I'm afraid that #include <iostream> pulls <unistd.h> in (using g++), even with flag -ansi.

It seems to me that g++ is not entirely ansi-compliant, because it's not supposed to pull symbols in that do not have a leading underscore.
 
I like Serena said:
I'm afraid that #include <iostream> pulls <unistd.h> in (using g++), even with flag -ansi.

It seems to me that g++ is not entirely ansi-compliant, because it's not supposed to pull symbols in that do not have a leading underscore.

Thanks I like Serena, that does indeed appear to be the case. Sort of surprising. I made a small test program and found out that <string> pulls it in. I then tried just <iostream> and it still pulled in the symbol. With no headers included, the problem went away. Bet a lot of the standard libraries have that problem.

I tried to trace it out through the header files, but haven't found it so far. Must be hidden in there somewhere.

I was going to craft a bug report, but I tried it out with gcc 4.6 and the problem is gone. So looks like an issue in 4.4 or other pre-4.6 compilers. Good to see they fixed it!

Anyways, thanks again!
 
Grep said:
I was going to craft a bug report, but I tried it out with gcc 4.6 and the problem is gone. So looks like an issue in 4.4 or other pre-4.6 compilers. Good to see they fixed it!

Anyways, thanks again!

Interesting! :smile:
I'm indeed using gcc version 4.4.3.
 
Have you considered searching /usr/include for a file containing crypt? (Possibly using grep. :-p)

EDIT: Nevermind. See attached file.
 

Attachments

TylerH said:
Have you considered searching /usr/include for a file containing crypt? (Possibly using grep. :-p)

EDIT: Nevermind. See attached file.

Well, duh! :smile:
 
tylerh said:
have you considered searching /usr/include for a file containing crypt? (possibly using grep. :-p)
lol!
 
So when I call grep it's our Grep who does the searching? Wow, you must be busy...:biggrin:
 
jhae2.718 said:
So when I call grep it's our Grep who does the searching? Wow, you must be busy...:biggrin:

I'm in ur computer searchin' ur filez!

(With an apology for writing like a WoW player on trade chat :eek:)
 
  • #10
Grep said:
(With an apology for writing like a WoW player on trade chat :eek:)

You couldn't be--you used the contraction "I'm" correctly :wink:
 

Similar threads

  • · Replies 39 ·
2
Replies
39
Views
5K
  • · Replies 6 ·
Replies
6
Views
12K
  • · Replies 118 ·
4
Replies
118
Views
10K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 25 ·
Replies
25
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
Replies
89
Views
7K
Replies
73
Views
6K
  • · Replies 30 ·
2
Replies
30
Views
5K