Edited by pointish, 27 January 2012 - 09:32 AM.
7 replies to this topic
#1
Posted 27 January 2012 - 05:22 AM
qqq
|
|
|
#2
Posted 27 January 2012 - 05:56 AM
1.
not right:
right:
not right:
Quote
scanf("%d", j);
right:
Quote
scanf("%d", &j);
#3
Posted 27 January 2012 - 06:01 AM
yex tnx have to remember this things
#4
Posted 27 January 2012 - 06:22 AM
Also
Type casting malloc and realloc is pretty useless as well since C does type coercion from void to any other type automatically.
string = realloc(string, capacity);Using the pointer to your old memory to hold the return value of a realloc call is bad form, if that call fails then realloc isn't required to clean up the old allocated memory and you just lost your pointer to it so now you have a memory leak. Most people will use a temp pointer to hold the realloc call to check if it's null and then move your original pointer to the temp one.
Type casting malloc and realloc is pretty useless as well since C does type coercion from void to any other type automatically.
"The best optimizer is between your ears" - Michael Abrash
Saying you can optimize a program is like saying you understand how a program works on every level of every facet on a specific machines configuration.
Saying you can optimize a program is like saying you understand how a program works on every level of every facet on a specific machines configuration.
#5
Posted 27 January 2012 - 06:36 AM
Sysop_fb said:
Type casting malloc and realloc is pretty useless as well since C does type coercion from void to any other type automatically.
#6
Posted 27 January 2012 - 06:48 AM
Yeah if you need clarity it can help if you know what you're doing.
It can cause problems as well and I usually recommend newer programmers to stay away from it. Depending on the compiler you're using if you cast malloc and forget to include the stdlib.h header file you could end up with broken code that compiles. Personally I'd just add a comment block if I need clarity that bad over telling the compiler that you're smarter than it via casting when it's not necessary.
FAQ: Casting malloc?
Question 7.7
It can cause problems as well and I usually recommend newer programmers to stay away from it. Depending on the compiler you're using if you cast malloc and forget to include the stdlib.h header file you could end up with broken code that compiles. Personally I'd just add a comment block if I need clarity that bad over telling the compiler that you're smarter than it via casting when it's not necessary.
FAQ: Casting malloc?
Question 7.7
"The best optimizer is between your ears" - Michael Abrash
Saying you can optimize a program is like saying you understand how a program works on every level of every facet on a specific machines configuration.
Saying you can optimize a program is like saying you understand how a program works on every level of every facet on a specific machines configuration.
#7
Posted 27 January 2012 - 06:59 AM
Yeah, right. Yeah, right. I did not think about it.
#8
Posted 27 January 2012 - 07:22 AM
hi i did some changes, is there a way to check that the memory allocation is succeeded?
because when i wright very big numbers it just ends the prog without gvining a message that allocation failed?!
because when i wright very big numbers it just ends the prog without gvining a message that allocation failed?!
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top










