Page 2 of 2 First 12
  • Jump to page:
    #16
  1. No Profile Picture
    status unknown
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    262
    Rep Power
    12
    Yes.
  2. #17
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Australia (Brisbane and Sydney)
    Posts
    11
    Rep Power
    0
    Cool... thanks.
  4. #18
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Australia (Brisbane and Sydney)
    Posts
    11
    Rep Power
    0

    SOLVED!!


    OK... now I'm going to embarrass all of us...

    It has been pointed out to me that I've had C99 available in my IDE all along. So it all should have worked. Except for one significant problem with the code (and this was pointed out to me as well)...

    I had declared my array:

    date_ints weekDates[2][weekCount];

    which has two indexes in the first dimension:

    weekDates[0][...]
    and
    weekDates[1][...]

    but my code is asking for &weekDates[2][5].

    Ooops... out of bounds!

    At least since you all missed it too, I don't feel so bad for missing it myself :)
  6. #19
  7. No Profile Picture
    Offensive Member
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Location
    in the perfect world
    Posts
    622
    Rep Power
    27
    >>Others have pointed out that you can't use a variable in an array declaration. However, variable length arrays were introduced in C99, and some compilers have permitted this as an extension for years. <<

    To compile you must have a complier that is up to date or it would have generated errors.

    MSVC.NET 2003 allows it if you use C (.c) files rather than C++ files (.cpp).

    It is IMHO bad coding practice and should be avoided.

    Code:
     date_ints  *pArray[2];
    
    for(i=0;i<2;i++)
    {
        pArray[i]=NULL;//ensure is null.
        pArray[i]=(date_ints*) malloc(sizeof(date_ints)*weekcount);
        if(!pArray[i])
           //error check all mem allocs
    }
    //use and then free memory before functin ends
    for(i=0;i<2;i++)
        free(pArray[i]);
    I prefer to use the WIN32 mem functions as they also tell you if they fail to free memory. A fail to free is a sign the memory has been incorrectly used.
    The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

    Frank Zappa
  8. #20
  9. No Profile Picture
    status unknown
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    262
    Rep Power
    12
    > To compile you must have a complier that is
    > up to date or it would have generated errors.

    Or put that another way, for it not to compile correctly you must be using an out of date compiler.

    > MSVC.NET 2003 allows it if you use C (.c) files
    > rather than C++ files (.cpp).
    >
    > It is IMHO bad coding practice and should be avoided.

    What's bad coding practice, variable length arrays? The alternative is to use dynamic memory allocation, which is error prone.

    > I prefer to use the WIN32 mem functions as they
    > also tell you if they fail to free memory. A fail to
    > free is a sign the memory has been incorrectly used.

    Hard to use on a non-Windows platform ;-)
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo