Now what I'm doing is a phone book manager and I'm very nervous with solid and clean code. I am trying to create a new memory allocation function,
flag FNEMM (zero ** PPV, size_ty size) {byte ** PPS = (byte **) PPV; #ifdef DEBUG {Insert (PPV! = Null & Size! = 0); } #endif * pps = (Byte *) Molec (size); #ifdef DEBUG {if (* pps! = NULL) MEMATets (* PPS, BGERBEZ, SIZE); } #endif return (* pps! = NULL); } Flag fNewPerInfoMem (perInfo ** ppv, size_t size) {#ifdef DEBUG {emphasis (PPV! = Null & size! = 0); } #endif * ppv = (pypho *) mlok (shape); #ifdef DEBUG {if (* ppv! = NULL) Mmateset (* PPV, Beaverbus, Size); } #endif return (* ppv! = NULL); } Flag fNewNodeMem (node ** ppv, size_ty shape) {#ifdef DEBUG {emphasis (ppv! = Null & size! = 0); } #endif * ppv = (node *) mauloq (shape); #ifdef DEBUG {if (* ppv! = NULL) Mmateset (* PPV, Beaverbus, Size); } #endif return (* ppv! = NULL); } The first is the base constraint and the other linked list is a node manufacturer
The last one is my own architecture maker <
I finally The last two have been made on the basis of the first two.
Is there any way that I can already use only one and I can do the work of the last two?
Some comments on your style:
-
#ifdef DEBUG is not required around emphasis . The complete number of entire is that you can do #define NDEBUG before inserting assert.h and all the claims are closed again. In general, #ifdef anywhere has an inline bad style in your code. If you need this, then it should be removed in the headers which define the macro as That the #ifdef argument is not repeated in your code - exactly like assert .h works. -
The assignment task, which is considered to be harmful because the zero ** argument is because they encourage collars to apply undefined behavior. To use this type of function correctly, you have to create a variable type of type and type its address at the function. For example:
foo * times; Zero * tmp; Flag results = FNEMM (& amp; TMP; Size * times); Bar = tmp; It is friction and ugly, so everyone goes to cheat and write which implies undefined behavior by violating aliasing rules:
Foo * times; Flag result = FNEMM ((zero **) and bar, size * bar); I would say that the whole function fNewMem is not really a purpose. Simply use the malloc one of the key principles of writing code in a language is that instead of knowing the idiom, it should try to rebuild them.
No comments:
Post a Comment