トップ «前の日記(2014-12-01) 最新 次の日記(2014-12-03)» 編集

ヨタの日々

2001|08|09|10|11|12|
2002|01|02|03|04|05|06|07|08|09|10|11|12|
2003|01|02|03|04|05|06|07|08|09|10|11|12|
2004|01|02|03|04|05|06|07|08|09|10|11|12|
2005|01|02|03|04|05|06|07|08|09|10|11|12|
2006|01|02|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|04|05|06|07|08|09|10|11|12|
2021|01|02|03|04|05|06|07|08|09|10|11|12|
2022|01|02|03|04|05|06|07|08|09|10|11|12|
2023|01|02|03|04|05|06|07|08|12|
2024|01|02|03|04|

2014-12-02 :-(

_ 午前

0530 起床

0700 食堂

0830 労働

_ 午後

1300 労働

_

1700 退勤

1800 読書

2100 飯

_ [C]typedef char* PCHAR;

PCHAR PCHAR パッパパラパ♪

PCHAR PCHAR 踊るポンポコリン♪

_ [C]最初にアクセスしたときに領域確保する

Singleton ぽいものですがどうですかね。

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

enum
{
  BUFFER_MAX = 8,
};

char* buffer = NULL;

void errx( void )
{
  printf( "%s\n", strerror( errno ) );
  exit( 1 );
}

char* getInstance( void )
{
  if( buffer == NULL )
  {
    buffer = malloc( BUFFER_MAX );
    if( buffer == NULL )
    {
      errx();
    }
  }
  return buffer;
}

void destroy( void )
{
  if( buffer != NULL )
  {
    free( buffer );
  }
}

char read( int index )
{
  char* buf = getInstance();
  return buf[ index ];
}

void write( int index, char data )
{
  char* buf = getInstance();
  buf[ index ] = data;
}

int main(int ac, char** av)
{
  char data;
  
  atexit( destroy );
  
  write( 0, 1 );
  data = read( 0 );
  printf( "%d\n", data );
  
  write( 1, 2 );
  data = read( 1 );
  printf( "%d\n", data );

  return 0;
}
$ gcc c.c
$ ./a.exe
1
2
本日のツッコミ(全2件) [ツッコミを入れる]
_ エモエモ (2014-12-05 14:29)

オブジェクト指向ムズイっす

_ みわ (2014-12-05 21:28)

デザインパターンも合わせると腑に落ちるます。FactoryパターンとかObserverパターンとか( まあオブジェクト指向じゃなくても実装できるけど )