Jamin2112
- 973
- 12
Screenshot:
Here's a full code dump if you think the issue could depend on a line not shown in the screenshot: http://codepad.org/zSE1vobz
The discussion revolves around a coding issue related to an EXC_BAD_ACCESS error encountered in a program. Participants explore the potential causes of this error, particularly focusing on the use of the strcmp function and memory management practices in C and C++.
Participants generally agree on the importance of using the correct types for string functions, but there is a divergence in opinions regarding the merits of malloc versus new for memory allocation, indicating that multiple views remain on this topic.
Some participants highlight the limitations of the provided code snippet, noting that without additional context, it is difficult to fully diagnose the issue. There are also mentions of potential memory leaks that remain unresolved.
Mark44 said:strcmp compares two strings. You don't show enough code so that I can determine what rt->fx represents, but 'x' is a character constant. Since both args of strcmp are strings (i.e., of type char * or char []), strcmp attempts to access the characters that are pointed to by its two arguments. Passing in 'x' (which happens to have an ASCII code of 0x78) causes strcmp to attempt to access the byte at memory location 0x78. This causes the access error that you are seeing.
All of the string processing functions that are declared in string.h take pointers for their string arguments.
It's faster than new, by a lot. If your'e doing low level memory handling, it allows allows you to do some nice tricks such as explicitly saying when you want a constructor called, or weird things like replacing new, delete, new, delete <- actually allocates and frees memory twice with malloc, ctor, dtor, ctor, dtor, free <- reuses the memory.Carno Raar said:Why do people use malloc? :-)