| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Find a word |
-= Pete Replied to David Nugent about: Find a word =- G'day David > FA> char *txt;char *pat;char *ptr; > FA> txt = (char*) malloc(strlen(buf)+1); > FA> pat = (char*) malloc(strlen(wrd)+1); DN> Just out of interest, why cast the return from malloc()? If it DN> is because it has no prototype, then you should do the /correct/ DN> thing and include stdlib.h. I've always cast the return from malloc() to whatever type the receiving pointer was as i always assumed it had to be done? BTW just tried it without the cast and all worked without any warnings/errors being generated with the compiler (QC) set to highest warning level, looks like i'll save myself some typing in the future. DN> If the compiler implements it and stack space isn't going to be DN> a problem, you could use alloca() for the temporary strings. DN> alloca() is usually significantly faster than the standard heap DN> allocation functions, and freeing is automatic. I've never used alloca() in fact i never knew it existed till you just mentioned it, just looked it up and it comes with a warning, see below. ========== from QC online help ============ Use of the alloca function is not recommended. The function is supported only for source compatibility with earlier releases. Routines using alloca should be compiled with optimization turned off (i.e., with the /Od option). When you compile with optimization on (either by default or by using one of the /O options), the stack pointer may not be restored properly in functions that have no local variables and also reference the alloca function. To ensure that the stack pointer is properly restored, make sure that any function referencing alloca declares at least one local variable. ============================================ looks like without local varables the BP/SP reg's are not saved and restored when optimizations are turned on. -=Pete=- --- OMX/Blue Wave v2.12* Origin: Gates of Hell (3:713/914.16) SEEN-BY: 50/99 620/243 623/630 711/401 409 410 413 430 808 809 932 934 SEEN-BY: 712/508 515 713/111 317 601 611 615 618 700 826 888 914 714/906 SEEN-BY: 800/1 @PATH: 713/914 615 888 711/808 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.