Thread: C Program solution needed...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    3

    C Program solution needed...

    Hi friends,

    As i a writting small C program to pass the structure pointer in the functio
    n. i am endup with small problem, plz let me know how to crack this one?

    /////////////////
    Code:
    void function1(void *);
    void main()
    {
    	int size_offset = 0;
    	typedef struct 
    	{
    		int a;
    		int b;
    		int c;
    		char ch;
    	}A;
    
    	A *pst = NULL;
    	pst = (A*)malloc(sizeof(A)*1);
    
    	function1((void*)pst);
    }
    void function1(void *pStr)
    {
       // As i need to intialize the structure members. i want to access it's me
    mbers.
       // How can i know the structure's 
       // memory layout in this function? 
    
       //Conditions:
       //1. i do not want to declare the structure as global or static.
       //2. I will pass the structure pointer as void pointer.
    
    }
    thanks and Regards,
    vijay

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    You can't find out anything about a struct at runtime. Why do you want to do so?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    <vader voice>
    There's something familiar about this question - a feeling that I've seen it somewhere before
    </vader voice>
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    The C eater *munch*
    Join Date
    Oct 2006
    Posts
    101
    is this what they call de javu?

  5. #5
    Register User andor's Avatar
    Join Date
    Aug 2006
    Location
    Novi Sad
    Posts
    42
    Quote Originally Posted by Salem
    <vader voice>
    There's something familiar about this question - a feeling that I've seen it somewhere before
    </vader voice>
    I agree.

  6. #6
    Registered User
    Join Date
    Jun 2006
    Posts
    75

    Lightbulb

    Quote Originally Posted by Salem
    <vader voice>
    There's something familiar about this question - a feeling that I've seen it somewhere before
    </vader voice>
    You've seen it here: http://www.daniweb.com/techtalkforums/thread58444.html

  7. #7
    Registered User
    Join Date
    Oct 2006
    Posts
    3

    HI

    hi friends,
    thanks for the input.....


    same question is post by me in
    www.daniweb.com

    vijay

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 15
    Last Post: 05-13-2006, 09:28 PM
  2. Replies: 2
    Last Post: 05-10-2002, 04:16 PM
  3. redirection program help needed??
    By Unregistered in forum Linux Programming
    Replies: 0
    Last Post: 04-17-2002, 05:50 AM
  4. Program Ideas Needed
    By pkananen in forum C++ Programming
    Replies: 9
    Last Post: 02-24-2002, 10:08 PM