Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6922293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:23:15+00:00 2026-05-27T10:23:15+00:00

My problem is the following – I have this lines of code: // allocate

  • 0

My problem is the following – I have this lines of code:

// allocate a new vector
        Vector3I *theVector = (Vector3I*)calloc(1,sizeof(Vector3I));

        // write face's points to this vector
        *theVector[0] = a3dsFace->points[0];
        *theVector[1] = a3dsFace->points[1];
        *theVector[2] = a3dsFace->points[2];

In the points[] array are the values {0,1,2}. When I write them to the Vector3I at which I am pointing to I get {0,0,0}. Do you have any suggestions about what I am doing wrong?

EDIT: Some more details:

This is from lib3ds at: http://code.google.com/p/lib3ds/

struct Lib3dsFace {
    Lib3dsUserData user;    /*! Arbitrary user data */
    char material[64];      /*! Material name */
    Lib3dsWord points[3];   /*! Indices into mesh points list */
    Lib3dsWord flags;       /*! See Lib3dsFaceFlag, below */
    Lib3dsDword smoothing;  /*! Bitmask; each bit identifies a group */
    Lib3dsVector normal;
};

The a3dsFace is a Lib3dsFace struct.

And the points array is from this type:

 typedef unsigned __int16 Lib3dsWord

And my Pointer:

Vector3I* theVector

is

typedef int Vector3I[3];

I hope this will bring some light to the problem.

With kind regards.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:23:16+00:00Added an answer on May 27, 2026 at 10:23 am

    The below code does work and is a test of your code snippet. If something isn’t working, it could be a good idea to create a test like this, with hard-coded values for *a3dsFace, in order to narrow down your problem.

    #include <stdio.h>
    #include <stdlib.h>
    #include <stdint.h>
    
    typedef int Vector3I[3];
    typedef uint16_t Lib3dsWord;
    
    struct Lib3dsFace {
       /* ... */
       Lib3dsWord points[3];   /*! Indices into mesh points list */
       /* ... */
    };
    
    /* ... */
    struct Lib3dsFace some_face = { {0, 1, 2} };
    struct Lib3dsFace *a3dsFace = &some_face;
    /* ... */
    
    int main(void)
    {
       Vector3I *theVector = (Vector3I*)calloc(1,sizeof(Vector3I));
    
       (*theVector)[0] = a3dsFace->points[0];
       (*theVector)[1] = a3dsFace->points[1];
       (*theVector)[2] = a3dsFace->points[2];
    
       printf("theVector: %p, *theVector: %p, &(*theVector)[0]: %p\n", theVector, *theVector, &(*theVector)[0]);
    
       printf("RIGHT Addresses: %p, %p, %p\n", &(*theVector)[0], &(*theVector)[1], &(*theVector)[2]);
       printf("WRONG Addresses: %p, %p, %p\n", &*theVector[0], &*theVector[1], &*theVector[2]);
    
       printf("Values: %d, %d, %d\n", (*theVector)[0], (*theVector)[1], (*theVector)[2]);
    
       free(theVector);
    
       return 0;
    }
    

    Output:

    theVector: 0x1cd3010, *theVector: 0x1cd3010, &(*theVector)[0]: 0x1cd3010
    RIGHT Addresses: 0x1cd3010, 0x1cd3014, 0x1cd3018
    WRONG Addresses: 0x1cd3010, 0x1cd301c, 0x1cd3028
    Values: 0, 1, 2
    

    I put the addresses there so that you can see (*theVector)[0] is a valid way of accessing the first element of your dynamically allocated Vector3I.

    Perhaps you haven’t set a3dsFace->points properly and that’s why {0, 0, 0} is being copied. Note also that you have each element of a Vector3I as type int, and each point is of type uint16_t. You also don’t need to use calloc to zero the allocated memory, since you’re immediately after assigning values to them; you could just use malloc.

    Bottom line is you still haven’t provided enough code to find your exact problem, and you should add code to debug your code inside your code.

    EDIT: I accidentally had *theVector[0] which should have been and is now (*theVector)[0], since [] has higher precedence than *. Otherwise it’d cause undefined behaviour due to the fact you’re going past the bounds of the array, my bad. I don’t know how I forgot that when it was one of the main reasons I was going to post an answer before you made your edit. It worked, but if you ran it through a program like valgrind it’d tell you that something wasn’t quite right (even if it may have ran as expected).

    As you can see by the addresses outputted above, there’s quite a difference. For example having *theVector[1], which because of operator precedence is the same as *(theVector[1]), will mean that it’ll increment the address pointed to by theVector by 3 * sizeof(int) bytes (aka sizeof(Vector3I)), instead of just 1 * sizeof(int) in the (correct) case of (*theVector)[1]).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following problem Bundle bundle = new Bundle(); bundle.putString(url, someUrl); This works fine.
I have following problem, Code: String a=Yeahh, I have no a idea what's happening
i have following problem To decode the Biquinary code use the number 5043210. At
I have a problem following from my previous problem . I also have the
Imagine the following problem: You have a database containing about 20,000 texts in a
I have following problem: I have built a tabbar application with 4 tabs. I
Consider the following problem: A multi-line string $junk contains some lines which are encoded
I have the following problem: I have an HTML textbox ( <input type=text> )
Following problem: Website build with PHP/HTML working We want to change this site to
I have following problem: I want to check (C#) if a thread has finished

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.