Thread: Promblem with code

  1. #16
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by watchdogger View Post
    Yes, I changed the first one yeah but in the other parts I don't which arg to use because I don't use others...
    Right. So why do you have 7 arguments in the first place? Because you have three arrays, and each has a size argument, and then you need a result size as well.

    Oh, and a few more comments on your code:
    Code:
        pSize[0] = counter;  // return by pointer the size of the result array
    Whilst this does indeed set the location pointed to by pSize to counter, it is probably a better option to do:
    Code:
        *pSize = counter;  // return by pointer the size of the result array
    since pSize is not an array of one element, it is the address of a single integer. [and please do not allocate 1 integer's worth of space. Use a local variable and take it's address, e.g.
    Code:
    int resultSize; 
    ... 
    result = culc_U(...., &resultSize);
    Do not use standard names for variables:
    Code:
     size_t
    Bad name for a variable - there is a standard type called size_t. You wouldn't call a variable "int" or "float", would you?

    Code:
        int j, groups_num, size_u, size_x, size_y, size_z, size_exp = 0, size_t = 0, *p_size;
    Do not mix initialize and uninitialized variables on the same line - it's hard to follow (I personally also dislike LONG lists of variables on one line - if there are two or three closely connected variables, they may be on the same line - but not 8 different variables which aren't closely connected).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  2. #17
    Registered User
    Join Date
    Jan 2009
    Posts
    10
    Thanks again but to correct you I have 4 arrays not 3.

    That's the biggest change I need to work with now in the code.

    That's where my problem starts.

  3. #18
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Right - I didn't quite finish my post - I got sidetracked...


    What I meant to say is that perhaps you should look into having a more flexible approach to how you pass the arrays to the function - perhaps have a struct that holds a size and pointer to first element, and pass an array of this type of struct to the function(s) - that way, you can do culc_U for 1, 2, 3, 5 or 63 arrays. You would of course have to know how many structs there are in the array - but that's just another parameter [or make a struct which holds a pointer to another struct]. Now you do not need to change the number of arguments, no matter what number of arrays you pass in.

    Your correction: as far as I can see, you are passing culc_U with 3 arrays (a, b and c) and returning one - have I missed something?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #19
    Registered User
    Join Date
    Jan 2009
    Posts
    10
    yes, before I made changes the were only 2, the chanegs i made r only in the cucl_U in the other's there 2 , afterwords I will change all of the code to 3 arrays.
    Last edited by watchdogger; 01-31-2009 at 06:39 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  2. Obfuscated Code Contest: The Results
    By Stack Overflow in forum Contests Board
    Replies: 29
    Last Post: 02-18-2005, 05:39 PM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM