QueryCAT Logo
Search 5,000,000+ questions and answers.

Frequently Asked Questions

Can I use malloc/free instead of new/delete in C++?

FAQ on C/C++/Unix by Roseanne Zhang, Java Programmer Certifi...
When you use malloc, you must use sizeof(class or struct), and skipped the entire class/struct initialization process. However, many struct/class in C++ is no longer fixed size, such as string. You will make your code venerable for segmentation error. If you use malloc/free, usually, you code will compile, but get runtime error. When you are in OO, you must think in OO.

Can I free() pointers allocated with new? Can I delete pointers allocated with malloc()?

Freestore management, C++ FAQ Lite
It is perfectly legal, moral, and wholesome to use malloc() and delete in the same program, or to use new and free() in the same program. But it is illegal, immoral, and despicable to call free() with a pointer allocated via new, or to call delete on a pointer allocated via malloc(). Beware! I occasionally get e-mail from people telling me that it works OK for them on machine X and compiler Y. See similar questions...

What is the difference between new/delete and malloc/free?

Ans: Malloc/free do not know about constructors and destructors. New and delete create and destroy objects, while malloc and free allocate and deallocate memory. Ans: C++ allows for dynamic initialization of global variables before main() is invoked. It is possible that initialization of global will invoke some function. If this function crashes the crash will occur before main() is entered. See similar questions...

Why should I use new instead of trustworthy old malloc()?

Freestore management, C++ FAQ Lite
Constructors/destructors: unlike malloc(sizeof(Fred)), new Fred() calls Fred's constructor. Similarly, delete p calls *p's destructor. Type safety: malloc() returns a void* which isn't type safe. new Fred() returns a pointer of the right type (a Fred*). Overridability: new is an operator that can be overridden by a class, while malloc() is not overridable on a per-class basis. See similar questions...

Can I use my own malloc?

Programming Questions
If you define a function called malloc in your own code, and link with the DLL, the DLL will call your malloc. Needless to say, you will run into serious problems if your malloc is buggy. If you run any programs from the DOS command prompt, rather than from in bash, the DLL will try and expand the wildcards on the command line. This process uses malloc before your main line is started. See similar questions...

What's a free or cheap C compiler I can use?

Tools and Resources
A popular and high-quality free C compiler is the FSF's GNU C compiler, or gcc. An MS-DOS port, djgpp, is also available. As far as I know, there are versions of gcc for Macs and Windows machines, too. A very inexpensive MS-DOS compiler is Power C from Mix Software, 1132 Commerce Drive, Richardson, TX 75801, USA, 214-783-6001. A shareware MS-DOS C compiler is available from ftp.hitech.com.au/hitech/pacific. Registration is optional for non-commercial use. Archives associated with the comp. See similar questions...

Petzold has a new book, 'Programming Windows with C#'. Should I buy this instead?

Windows Programming FAQ
Win32 is the current environment of choice. Everything you can do in Windows can be done with Win32, so I would recommend 'Programming Windows, 5th edition' at the moment, for beginning Windows programmers. C# and .NET are well worth learning, but for the next couple of years, Win32 programming will be almost inescapable. I would move onto .NET only after having a solid grounding in Win32. In two or three years time, I may well revise that opinion - but not yet. See similar questions...

c In a call to malloc, what does an error like ''Cannot convert 'void *' to 'int *''' mean?

All Questions
I wrote a little wrapper around malloc, but it doesn't work: #include <stdio.h> #include <stdlib.h> mymalloc(void *retp, size_t size) { retp = malloc(size); if(retp == NULL) { fprintf(stderr, "out of memory\n"); exit(EXIT_FAILURE); } } I'm trying to declare a pointer and allocate some space for it, but it's not working. See similar questions...

Why do some universities use Modula-2 for teaching instead of C or C++?

Modula-2 FAQ
A1. Modula-2 is a type-safe language and its compilers will therefore catch many errors that otherwise show up only at run time. While professional programmers need to learn C++ because it is commonly used, it is important to begin a discipline of deliberate, engineered programming at the outset. Modula-2 is easier to write in, easier to read (it reads left to right) and easier to debug. It lends itself well to software engineering of very large projects. See similar questions...

Is C++ a superset of C? Can I use a C++ compiler to compile C code?

Infrequently Asked Questions in comp.lang.c
C++ is a superset of something, we're not sure what. You can use a C++ compiler to compile C code, but the results may surprise you. See similar questions...

I get SIGSEGV in malloc, calloc, realloc, or free. Are they buggy?

Unofficial comp.os.linux.development.* FAQ
No, they are probably not buggy. These four functions are some of the most often used code in the entire system. If there were any major bugs, they would have been found and fixed long ago. When one of these functions produce a SIGSEGV in more than 99% of the cases it will be a bug in your code. Imagine one of the following situations: You free some memory twice. In all these cases, you damage the internal data structures used by malloc and friends. See similar questions...

Can I use LessTif with C++ ?

LessTif Frequently Asked Questions
You sure can. There really are two ways. You can use it directly, or through one of the C++ wrappers for Motif. Much of this is discussed in the Motif FAQ which can be found at Ken Lee's website at http://www.rahul.net/~kenton Using LessTif directly with C++ prompts the question on how to use class member functions as callbacks. See similar questions...

Why not use chlorine instead?

Water Filters, Purifiers, and Purification FAQ
Chlorine changes the tastes and odor of water. Chlorination can also produce harmful by-products called Trihalomethanes (THMs) which are linked to incidence of cancer. No, the UV unit will use about the same amount of energy as a 60 watt light bulb. It is a cost effective, natural way to increase water quality where microbiological contamination is present and to provide peace of mind where microbiological contamination is a greater risk. See similar questions...

Why should I use a Mohel instead of a doctor?

Frequently Asked Questions - Emoil.com/Emohel.com
The mohel is a super-specialist, an expert at his profession, who probably possesses more experience at performing circumcisions than most doctors. A mohel may have the opportunity to perform more brisses in a month than some doctors do in an entire year. Doctors may be called away on medical emergencies and have to cancel their participation in your child's circumcision at the last minute. See similar questions...

Why do you use a DTD instead of a schema?

MusicXML FAQ (Frequently Asked Questions)
When we started developing MusicXML, a DTD (Document Type Definition) was the only official W3C recommendation for defining an XML document. Since that time, XML Schemas have become an official W3C recommendation, and alternative schema languages like RELAX NG have also become available. W3C XML Schemas offer many benefits when using XML in electronic commerce and business database applications. For musical documents, though, the advantages are less compelling. See similar questions...

Why do you use all these elements instead of attributes?

MusicXML FAQ (Frequently Asked Questions)
This is mainly a stylistic decision. Several XML books advise representing semantics in elements rather than attributes where possible. One advantage of doing this is that elements have structure, but attributes do not. If you find that what you are representing really has more than one part, you can create a hierarchical structure with an element. With attributes, you are limited to an unordered list. See similar questions...

Can I use Microsoft .NET C compiler (MS-VC7) instead of MS-VC6++ ?

VFS FAQ - FlagShip Frequently Asked Support Questions
Sorry, you cannot. Both Microsoft compilers are incompatible to each other and produce different objects. But if you haven't MS-VC6++ you can use the free Borland BCC32 compiler. When compiling with BCC port of FlagShip, the linker reports "Fatal: Unable to open file KERNEL32.LIB" Most probably,. you have created the BCC config files bcc32.cfg and ilink32.cfg in the C:\Borland\Bcc55\bin directory by your self, didn't you? If so, rename them to e.g. bcc32_cfg.old and ilink32_cfg. See similar questions...

Why should I use MapPoint instead of free maps on the Internet?

MapPoint FAQs
Although MapPoint maps can be seen on the Internet at sites such as Expedia, running MapPoint locally gives users ultimate convenience in locating destinations, finding nearby places, and integrating maps into their day-to-day business. MapPoint launches and locates addresses instantly, avoiding slow Internet connections or the inability to get the right-sized maps for the users' needs. The print options in MapPoint offer unique flexibility and precision in representing data and locations. See similar questions...

Why shouldn’t I use a free video hosting service instead of yours?

Add video to a website - Frequently Asked Questions
There are several drawbacks imposed by using free video publishing services like Google Video, YouTube etc. Advertising - these services feed themselves on advertising and they will advertise to your customers too. In many businesses it is highly unprofessional and unrespectable to use such services. Quality - these video services convert your videos to low quality and the playback is not impressive. It is good for teenager clips and video shot by phone, but nothing more. See similar questions...

Why should I use UTS Webmail instead of some other free web email facility?

UTS: Frequently Asked Questions
A number of free web email facilities are available. Your UTS Email Account and UTS Webmail offer the following benefits: UTS Email accounts are one of the offical ways of the university to communicate with staff and students on news, events and information concerning study and university life. UTS Webmail is considerably more reliable than most free web mail services, especially for mail within UTS. All web email type products have a quota for the amount of email you can store. See similar questions...

Explore Other Topics

What is tap-tuning and why is it relevant to solid body electric guitar making?
How can I tell if I'm using the correct SpeakonŽ cable?
HOW DO I BECOME A TATTOO ARTIST?
Q.4What is 'FOB JAPAN'?
How do I get rid of air bubbles?
How do I adjust my aftermarket roller rockers?
What are the advantages of using a USB Flash Drive instead of an External Hard Drive?
Q.1.27 Where can I pay the visa fee?
If the non-custodial parent is not paying child support, what can I do?
Can I, or should I, invest in a Roth IRA if I currently contribute to a 401(k)?
If I buy a home with hardwood floors, how can I tell if they have a wax or urethane finish?
What is a submittal?
Q What's the hair made of?
More Questions >>

© Copyright 2007-2012 QueryCAT
About • Webmasters • Contact