構造体とメモリ


  構造体の大きさ




  

#include <stdio.h>
#include <memory.h>
#include <string.h>
#include <stdlib.h>

struct MYDATA {
	char	type_1;
	short	type_2;
	long	type_3;
	int	type_4;
	float	type_5;
	double	type_6;
};

int main( int argc, char *argv[] )
{

	struct	MYDATA md;
	int	allsize;

	printf( "MYDATA の大きさは %d\n", sizeof( struct MYDATA ) );

	allsize = 
		sizeof( char ) + 
		sizeof( short ) + 
		sizeof( long ) +
		sizeof( int ) + 
		sizeof( float ) + 
		sizeof( double );

	printf( "MDATA のメンバの大きさの合計は %d\n", allsize );

	return 0;
}
  

  

MYDATA の大きさは 24
MDATA のメンバの大きさの合計は 23
  

  初期化しない構造体の中身




  

#include <stdio.h>

struct MYDATA {
	char	type_1;
	short	type_2;
	long	type_3;
	int	type_4;
	float	type_5;
	double	type_6;
};

int main( int argc, char *argv[] )
{

	struct	MYDATA md;
	FILE *fp;

	fp = fopen( "MYDATA", "wb" );
	if ( fp == NULL ) {
		return 1;
	}

	fwrite( &md, sizeof( struct MYDATA ), 1, fp );

	fclose( fp );

	return 0;
}
  

          0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
--------------------------------------------------------------------------
00000000 D4 B5 F5 77 30 A7 E3 77 68 07 00 00 2B 85 09 61  ヤオ.w0ァ縢h...+..a
00000010 68 07 00 00 FF FF FF FF                          h.......


  初期化した構造体の中身

  

#include <stdio.h>

struct MYDATA {
	char	type_1;
	short	type_2;
	long	type_3;
	int	type_4;
	float	type_5;
	double	type_6;
};

int main( int argc, char *argv[] )
{

	struct	MYDATA md;
	FILE *fp;

	fp = fopen( "MYDATA", "wb" );
	if ( fp == NULL ) {
		return 1;
	}

	md.type_1 = 0;
	md.type_2 = 0;
	md.type_3 = 0;
	md.type_4 = 0;
	md.type_5 = 0;
	md.type_6 = 0;

	fwrite( &md, sizeof( struct MYDATA ), 1, fp );

	fclose( fp );

	return 0;
}
  

          0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
--------------------------------------------------------------------------
00000000 00 B5 00 00 00 00 00 00 00 00 00 00 00 00 00 00  .オ..............
00000010 00 00 00 00 00 00 00 00                          ........

  値をセットした構造体の中身

  

#include <stdio.h>

struct MYDATA {
	char	type_1;
	short	type_2;
	long	type_3;
	int	type_4;
	float	type_5;
	double	type_6;
};

int main( int argc, char *argv[] )
{

	struct	MYDATA md;
	FILE *fp;

	fp = fopen( "MYDATA", "wb" );
	if ( fp == NULL ) {
		return 1;
	}

	md.type_1 = 8;
	md.type_2 = 9;
	md.type_3 = 10;
	md.type_4 = 11;
	md.type_5 = 12;
	md.type_6 = 13;

	fwrite( &md, sizeof( struct MYDATA ), 1, fp );

	fclose( fp );

	return 0;
}
  

          0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
--------------------------------------------------------------------------
00000000 08 B5 09 00 0A 00 00 00 0B 00 00 00 00 00 40 41  .オ............@A
00000010 00 00 00 00 00 00 2A 40                          ......*@

  関数に引き渡された構造体

  

#include <stdio.h>

struct MYDATA {
	char	type_1;
	short	type_2;
	long	type_3;
	int	type_4;
	float	type_5;
	double	type_6;
};

void WriteMyData( struct MYDATA *pmd, FILE *fp );

int main( int argc, char *argv[] )
{

	struct	MYDATA md;
	FILE *fp;

	fp = fopen( "MYDATA", "wb" );
	if ( fp == NULL ) {
		return 1;
	}

	WriteMyData( &md, fp );

	fclose( fp );

	return 0;
}

void WriteMyData( struct MYDATA *pmd, FILE *fp )
{

	pmd->type_1 = 8;
	pmd->type_2 = 9;
	pmd->type_3 = 10;
	pmd->type_4 = 11;
	pmd->type_5 = 12;
	pmd->type_6 = 13;

	fwrite( pmd, sizeof( struct MYDATA ), 1, fp );

}
  




yahoo  google  MSDN  MSDN(us)  WinFAQ  Win Howto  tohoho  ie_DHTML  vector  wdic  辞書  天気 


[sc]
CCBot/2.0 (https://commoncrawl.org/faq/)
24/12/09 06:31:44
InfoBoard Version 1.00 : Language=Perl

1 BatchHelper COMprog CommonSpec Cprog CprogBase CprogSAMPLE CprogSTD CprogSTD2 CprogWinsock Cygwin GameScript HTML HTMLcss InstallShield InstallShieldFunc JScript JScriptSAMPLE Jsfuncs LLINK OldProg OracleGold OracleSilver PRO PRObrowser PROc PROconePOINT PROcontrol PROftpclient PROjscript PROmailer PROperl PROperlCHAT PROphp PROphpLesson PROphpLesson2 PROphpLesson3 PROphpfunction PROphpfunctionArray PROphpfunctionMisc PROphpfunctionString PROsql PROvb PROvbFunction PROvbString PROvbdbmtn PROvbonepoint PROwebapp PROwin1POINT PROwinSYSTEM PROwinYOROZU PROwindows ProjectBoard RealPHP ScriptAPP ScriptMaster VBRealtime Vsfuncs a1root access accreq adsi ajax amazon argus asp aspSample aspVarious aspdotnet aw2kinst cappvariety centura ckeyword classStyle cmaterial cmbin cmdbapp cmenum cmlang cmlistbox cmstd cmstdseed cmtxt cs daz3d db dbCommon dbaccess dnettool dos download flex2 flex3 flex4 framemtn framereq freeWorld freesoft gimp ginpro giodownload google hdml home hta htmlDom ie9svg install java javaSwing javascript jetsql jquery jsp jspTest jspVarious lightbox listasp listmsapi listmsie listmsiis listmsnt listmspatch listmsscript listmsvb listmsvc memo ms msde mysql netbeans oraPlsql oracle oracleWiper oraclehelper orafunc other panoramio pear perl personal pgdojo pgdojo_cal pgdojo_holiday pgdojo_idx pgdojo_ref pgdojo_req php phpVarious phpguide plsql postgres ps r205 realC realwebapp regex rgaki ruby rule sboard sc scprint scquest sdb sdbquest seesaa setup sh_Imagick sh_canvas sh_dotnet sh_google sh_tool sh_web shadowbox shgm shjquery shvbs shweb sjscript skadai skywalker smalltech sperl sqlq src systemdoc tcpip tegaki three toolbox twitter typeface usb useXML vb vbdb vbsfunc vbsguide vbsrc vpc wcsignup webanymind webappgen webclass webparts webtool webwsh win8 winofsql wmi work wp youtube