GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 24-Aug-2005, 04:35
ganesh_ghodke ganesh_ghodke is offline
New Member
 
Join Date: Aug 2005
Posts: 6
ganesh_ghodke is on a distinguished road
Lightbulb

problem of c structure in .net


Hello,

I am working on c project. it currently shifted from Linux to windows and compiled in .net 2003. after running code, I got problem in printing value of double member which is present in structure. at debug time , i seen that value coming in to double variable but can't print by any type specifier like %f,%g etc. it's problem with structure declaration. if change location of double from middle to end of struct, it work!

Can any one explain me why this happen? (I got solution for this problem using pragma pack directive. but i have to know, why this happen only with .net not on gcc or other c compiler.) This is related to boundary setting of structure. plz help me to understand. Thanks.

Cheers,
  #2  
Old 24-Aug-2005, 08:06
maprich maprich is offline
Member
 
Join Date: May 2005
Posts: 163
maprich has a spectacular aura aboutmaprich has a spectacular aura about
Since your question is .NET related, please go to this forum.

And please post them also snippets of your code so that your question can be more readily answered.
  #3  
Old 25-Aug-2005, 01:12
ganesh_ghodke ganesh_ghodke is offline
New Member
 
Join Date: Aug 2005
Posts: 6
ganesh_ghodke is on a distinguished road
plz reply some thing, so that i can got some hint!
thanks.
  #4  
Old 25-Aug-2005, 02:10
LuciWiz's Avatar
LuciWiz LuciWiz is online now
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 961
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough
Quote:
Originally Posted by ganesh_ghodke
plz reply some thing, so that i can got some hint!
thanks.

I will only move this thread to the .NET Forum, if the code uses Managed Extensions; since you were able to port it to the new VC compiler (7.x is part of VS.NET, but it has 2 components, and the one you used is just a revised version of the plain c++ compiler from the previous versions) from gcc - I guess not.
maprich asked you to show us the code you used; there's no way we can figure it out without seeing what you did.

Best regards,
Lucian
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #5  
Old 25-Aug-2005, 05:15
ganesh_ghodke ganesh_ghodke is offline
New Member
 
Join Date: Aug 2005
Posts: 6
ganesh_ghodke is on a distinguished road
Quote:
Originally Posted by LuciWiz
I will only move this thread to the http://www.gidforums.com/f-49.html, if the code uses Managed Extensions; since you were able to port it to the new VC compiler (7.x is part of VS.NET, but it has 2 components, and the one you used is just a revised version of the plain c++ compiler from the previous versions) from gcc - I guess not.
maprich asked you to show us the code you used; there's no way we can figure it out without seeing what you did.

Best regards,
Lucian

Thanks for reply. the code for struct is like

CPP / C++ / C Code:
 typedef struct my_info {
  time_t tim;

  int sent;
  int received;
  int sent;
  int received;
 
    #if defined(MON) 
    double b_sent;        //this double gives problem (for int data type it work)
    #else 
    int b_sent;
    #endif
    
    int b_received;
    int all_mem;
    int max_mem;
  
  int length;
  int size;
  int count;
  
  int conns;		
  int conn_info;		
  CONN_INFO *conn_info;   //anther structure pointer
} INFO;

anther structure which contain double it work fine. if i move this double varible at end of struct it work.

thanks.
Last edited by LuciWiz : 25-Aug-2005 at 12:47. Reason: Please insert your C code between [c] & [/c] tags
  #6  
Old 25-Aug-2005, 09:56
maprich maprich is offline
Member
 
Join Date: May 2005
Posts: 163
maprich has a spectacular aura aboutmaprich has a spectacular aura about
Please post also:
  1. The code that declares a variable of type INFO
  2. The code that assigns value to your structure member "b_sent"
  3. The code that prints out the structure member "b_sent"

Because the structure itself seems to be valid

Please use code tags [c] and [/c] to make your code readable.
  #7  
Old 26-Aug-2005, 03:58
ganesh_ghodke ganesh_ghodke is offline
New Member
 
Join Date: Aug 2005
Posts: 6
ganesh_ghodke is on a distinguished road
Thanks for reply. I am not sending code because nothing is wrong in code only problem related to .net.

After debugging code, I got problem in pointer addressing. when i copy information to structure pointer A and address of A is assign to other structure pointer B. The values are copied successfully but only value of double member of A is printed but not by B.

code is like

CPP / C++ / C Code:
 function1()
{

INFO *B;

             //some code statement

get_info(&b);

            //print info of B         (Double member print 0 value)
}

get_info( INFO **B)
{
INFO *A;
           //enter info in to A structure member

//print A value        (*****it works)
*B=&A;

}
Last edited by LuciWiz : 26-Aug-2005 at 04:11. Reason: Please insert your C code between [c] & [/c] tags
  #8  
Old 26-Aug-2005, 05:14
ganesh_ghodke ganesh_ghodke is offline
New Member
 
Join Date: Aug 2005
Posts: 6
ganesh_ghodke is on a distinguished road
Lightbulb

Also one thing,
The get_info() function in another c file and function1() in another c file. the structure in get_info() function file declared static. is there any problem in accessing value using address from different c files in same project?
 
 

Recent GIDBlogPython ebook by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Airport Log program using 3D linked List : problem reading from file batrsau C Programming Language 11 29-Feb-2008 08:44
Introduction to .NET LuciWiz .NET Forum 5 09-Aug-2007 05:53
Visual Studio .NET 2003 problem in executing C source files Debugger1 C Programming Language 14 04-Jun-2005 03:51
Repetition structure problem and question brookeville C++ Forum 17 29-Oct-2004 18:48
[CONTEST?]Data Structure Test dsmith C Programming Language 2 06-Jun-2004 16:13

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 11:13.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.