![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: Helltown
Posts: 162
Rep Power: 4
![]() |
c++ header standards
Ok this is one of those stupid questions but #include <memory> or #include <memory.h> in c++?
I try to compile with memory in dev c++ and it complains and then when I try in vc++ 2008 it complains about undefined functions with memory.h
__________________
Spread your wings and fly! Chicken! |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,223
Rep Power: 5
![]() |
Re: c++ header standards
Neither. There is no standard header named <memory.h> specified in either the C or C++ standards. The C++ standard also specifies no standard header named <memory> or <cmemory>.
If you are trying to access functions like memset(), the relevant C header is <string.h> (which is deprecated in C++ and replaced by <cstring> which has the functions living in namespace std). |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: Helltown
Posts: 162
Rep Power: 4
![]() |
Re: c++ header standards
i c
thanks what about functions like malloc/free/realloc?
__________________
Spread your wings and fly! Chicken! |
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,223
Rep Power: 5
![]() |
Re: c++ header standards
malloc(), calloc(), realloc(), and free() are declared within <stdlib.h> (C, deprecated in C++) and <cstdlib> (C++, also in namespace std).
Surely, your compiler documentation would have had some mention of those functions. |
|
|
|
|
|
#5 | |
|
PFO God In Training
![]() Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 549
Rep Power: 4
![]() |
Re: c++ header standards
Quote:
__________________
True Terror is to wake up one morning and discover that your high school class is running the country - Kurt Vonnegut Jr. |
|
|
|
|
|
|
#6 |
|
Not a user?
Join Date: Sep 2007
Posts: 272
Rep Power: 2
![]() |
Re: c++ header standards
|
|
|
|
|
|
#7 |
|
Hobbyist Programmer
Join Date: Jan 2006
Location: UK
Posts: 215
Rep Power: 3
![]() |
Re: c++ header standards
No. Malloc and new are different, and both have their place in C++, there are a number of differnces between the two.
new is an operator, that constructs an object and is type safe. malloc is a function, malloc just allocates memory, it doesn't call the objects constructer, and returns a void pointer to the memory which is required to be explicitly cast. |
|
|
|
|
|
#8 |
|
Not a user?
Join Date: Sep 2007
Posts: 272
Rep Power: 2
![]() |
Re: c++ header standards
Just goes to show don't believe everything you hear...
|
|
|
|
|
|
#9 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,223
Rep Power: 5
![]() |
Re: c++ header standards
Quote:
The return value from malloc() does not require explicit casting (or conversion) in C, although it does in C++.
__________________
Dear God So far today I've done all right. I haven't been grumpy yet. But in a few minutes, God, I'm going to get out of bed, and from then on I'm going to need a lot more help. AMEN |
|
|
|
|
|
|
#10 |
|
Professional Programmer
![]() Join Date: Sep 2005
Posts: 419
Rep Power: 4
![]() |
Re: c++ header standards
>The C++ standard also specifies no standard header named <memory> or <cmemory>.
You might want to double check that. A header called <memory> does indeed exist. It's where you find such useful creatures as auto_ptr and allocator.
__________________
Even if the voices aren't real, they have some pretty good ideas. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| C++ time.h header | Jabo | C++ | 3 | Jun 19th, 2008 8:23 PM |
| How do I silence header? | stu7398 | PHP | 4 | Jan 13th, 2008 6:15 PM |
| Coding standards without control? | martinig | Other Programming Languages | 1 | Dec 4th, 2006 7:04 AM |
| question about header files and prototyping functions | linuxpimp20 | C | 13 | Sep 7th, 2005 8:28 AM |
| TCP Header for Echo Communication | AusTex | C++ | 0 | Feb 27th, 2005 3:57 PM |