{"id":205570,"date":"2013-12-10T20:28:03","date_gmt":"2013-12-10T16:28:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=205570"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=205570","title":{"rendered":"<span class=\"post_title\">Object oriented C<\/span>"},"content":{"rendered":"<div class=\"content html_format\"> \t\t\t\u0412\u0430\u043c \u0434\u0430\u043b\u0438 \u0437\u0430\u0434\u0430\u043d\u0438\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043d\u0430 \u0421, \u0430 \u0432\u044b \u0443\u0436\u0435 \u0437\u0430\u0431\u044b\u043b\u0438 \u043a\u0430\u043a \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u0432 \u0442\u0435\u043a\u0441\u0442\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0435\u0442 \u043d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 class \u0438\u043b\u0438 virtual? \u0418\u043b\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b \u0432\u043b\u044e\u0431\u043b\u0435\u043d\u044b \u0432 \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u0443 \u0438 \u0441\u0442\u0440\u043e\u0433\u043e\u0441\u0442\u044c ANSI C, \u043d\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u0432\u0430\u043c \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u044f\u0437\u044b\u043a\u043e\u0432 \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0441\u043e\u043a\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f? \u0418\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u043d\u0430 \u0441\u0442\u0430\u0440\u044b\u0439 \u0434\u043e\u0431\u0440\u044b\u0439 \u0421 \u0441 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b? \u0412 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043f\u0440\u0438\u0435\u043c\u043e\u0432, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0430 C \u0432\u043f\u043e\u043b\u043d\u0435 \u043c\u043e\u0436\u043d\u043e \u0434\u0443\u043c\u0430\u0442\u044c \u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u043e-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0444\u0443\u043a\u0446\u0438\u044e \u0441\u0436\u0438\u043c\u0430\u044e\u0449\u0443\u044e \u0434\u0430\u043d\u043d\u044b\u0435. \u0414\u0430\u043d\u043d\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0441\u0436\u0438\u043c\u0430\u0442\u044c\u0441\u044f \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430\u043c\u0438. \u041f\u0440\u0438 \u0441\u043c\u0435\u043d\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u043a\u043e\u0434 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0435 \u0434\u043e\u043b\u0436\u0435\u043d \u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f. \u0416\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0447\u0442\u043e\u0431\u044b \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043c\u0435\u043d\u044f\u0442\u044c \u00ab\u043d\u0430 \u043b\u0435\u0442\u0443\u00bb.<br \/>  \u041d\u0430 \u0421++ \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u043e \u0431\u044b \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code>class compressor {   public:     void compress(void* data)=0;     void uncompress(void* data)=0;     void status()const=0; };  class rar_compressor : public compressor {...};  class zip_compressor : public compressor {...};  void do_compress(compressor* c, void* in_data, void* out_data) {   c-&gt;compress(in_data);   c-&gt;uncompress(out_data);   c-&gt;status(); } <\/code><\/pre>\n<p>  \u0418\u043b\u0438 \u0442\u0430\u043a:<\/p>\n<pre><code>template&lt;typename Cmp&gt; void do_compress(Cmp& c, void* in_data, void* out_data) {   c.compress(in_data);   c.uncompress(out_data);   c.status(); } <\/code><\/pre>\n<p>  \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u0441\u0445\u0435\u043c\u0443 \u043d\u0430 \u0421. <\/p>\n<pre><code>#compressor_interface.h  typedef struct compressor_t {   \/\/ `public` interface   void (*compress)(struct compressor_t*, void* data);   void (*uncompress)(struct compressor_t*, void* data);   void (*status)(struct compressor_t*);   \/\/ `private` part   void* impl_; } compressor_t; <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u0432\u0441\u0435 \u0434\u0435\u0442\u0430\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <br \/>  \u0441\u043a\u0440\u044b\u0442\u044b \u0437\u0430 `impl_`.<br \/>  \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u00ab\u043a\u043b\u0430\u0441\u0441\u044b\u00bb.  <\/p>\n<pre><code>#rar.h void rar_init(compressor_t* c, int cr); void rar_free(compressor_t* c); <\/code><\/pre>\n<pre><code>#rar.c  typedef struct {   int compressed_ratio;   int error;   int time_to_finish; } rar_impl_t;  \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/  \/\/ \u0423\u0434\u043e\u0431\u043d\u044b\u0439 \u043c\u0430\u043a\u0440\u043e\u0441 \u0434\u043b\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0435\u0433\u043e\u0441\u044f \u043a\u043e\u0434\u0430 #define PREPARE_IMPL(c) \\   assert(c); \\   assert(c-&gt;impl_); \\   rar_impl_t* impl = (rar_impl_t*)c-&gt;impl_;  \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/  static void compress(compressor_t* c, void* data) {   PREPARE_IMPL(c)   printf(&quot;RAR: compressor working. Compressed ratio: %d\\n&quot;,           impl-&gt;compressed_ratio); }  \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/  static void uncompress(compressor_t* c, void* data) {   PREPARE_IMPL(c)   printf(&quot;RAR: uncompressor working. Will be finished in %d.\\n&quot;,           impl-&gt;time_to_finish); }  \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/  static void status(compressor_t* c) {   PREPARE_IMPL(c)   printf(&quot;Compressed ratio: %d, error: %d\\n&quot;, impl-&gt;compressed_ratio,          impl-&gt;error); }  \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/  \/\/ \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 void rar_init(compressor_t* c, int cr) {   assert(c);   c-&gt;impl_ = malloc(sizeof(rar_impl_t));   rar_impl_t* impl = (rar_impl_t*)c-&gt;impl_;      \/\/ \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c `private` \u0447\u043b\u0435\u043d\u044b   impl-&gt;time_to_finish = 5;   impl-&gt;compressed_ratio = cr;   impl-&gt;error = 0;    \/\/ \u0418 `public` \u0444\u0443\u043d\u043a\u0446\u0438\u0438   c-&gt;compress = &compress;   c-&gt;uncompress = &uncompress;   c-&gt;status = &status; }  \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/   \/\/\u0414\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 void rar_free(compressor_t* c) {   PREPARE_IMPL(c)   free(impl); } <\/code><\/pre>\n<p>  \u00ab\u041a\u043b\u0430\u0441\u0441\u00bb zip \u0443\u0441\u0442\u0440\u043e\u0435\u043d \u0442\u0430\u043a\u0438\u043c \u0436\u0435 \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u0435\u0433\u043e \u043a\u043e\u0434 \u0442\u0443\u0442 \u043d\u0435 \u0431\u0443\u0434\u0443. \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0447\u0442\u043e \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043f\u043e\u0434\u0447\u0435\u0440\u043a\u043d\u0443\u0442\u044c \u00ab\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b\u00bb \u044d\u0442\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0439-\u0447\u043b\u0435\u043d\u043e\u0432, \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u043d\u044b \u0438\u043c\u0435\u0442\u044c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u0443\u044e \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443, \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u0438\u0445 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u00ab\u043a\u043b\u0430\u0441\u0441\u0430\u00bb.<\/p>\n<p>  \u0418 \u0442\u0435\u043f\u0435\u0440\u044c \u043a\u043e\u0434 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code>void work(compressor_t* c, void* data_to_compress, void* data_to_decompress) {   c-&gt;compress(c, data_to_compress);   c-&gt;uncompress(c, data_to_decompress);   c-&gt;status(c); }  int main() {     void* uncompressed_data[DATA_SIZE];     void* compressed_data[DATA_SIZE];      compressor_t rar;     rar_init(&rar, COMP_RATIO);     work(&rar, uncompressed_data, compressed_data);     rar_free(&rar);      printf(&quot;\\n&quot;);      compressor_t zip;     zip_init(&zip, VOLUMES);     work(&zip, uncompressed_data, compressed_data);     zip_free(&zip);      return 0; } <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u043d\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0443\u0436\u0435 \u0437\u0430\u043c\u0435\u0442\u0438\u043b, \u0447\u0442\u043e \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0438 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0432\u0442\u043e\u0440\u043e\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 <i>compressor_t zip<\/i>, \u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 <i>rar<\/i>, \u0438 \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u043f\u0440\u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0434\u043c\u0435\u043d\u0438\u0442\u044c \u043e\u0434\u043d\u0443 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u00ab\u043d\u0430 \u043b\u0435\u0442\u0443\u00bb. \u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0441\u0445\u0435\u043c\u0443 \u0431\u043e\u043b\u0435\u0435 \u0433\u0438\u0431\u043a\u043e\u0439 \u0447\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u0421++. \u0422\u0430\u043a\u0436\u0435 \u0432\u044b \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0437\u0430\u043c\u0435\u0442\u0438\u043b\u0438, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0439 <br \/>  \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u00ab\u0421\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f\u00bb.<\/p>\n<p>  \u0422\u0430\u043a \u0445\u043e\u0440\u043e\u0448\u043e, \u0441 \u0434\u0432\u0443\u043c\u044f \u0438\u0437 \u0442\u0440\u0435\u0445 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0445 \u041e\u041e\u041f (\u0432\u044b \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u043f\u043e\u043c\u043d\u0438\u0442\u0435 \u0438\u0445 \u043d\u0430\u0438\u0437\u0443\u0441\u0442\u044c?) \u043c\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c. \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u2014 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435. \u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u0438\u043c\u0438 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438, \u044f \u043e\u043f\u0438\u0448\u0443 \u0437\u0434\u0435\u0441\u044c \u0442\u043e\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043d\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u044b\u043c.<\/p>\n<p>  \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u043f\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0421, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0443\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u043d\u043e\u043d\u0438\u043c\u043d\u044b\u0435 \u0447\u043b\u0435\u043d\u044b-\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0447\u043b\u0435\u043d\u043e\u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 (\u0432 gcc \u0432\u0430\u043c, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0444\u043b\u0430\u0433 &quot;-std=c11&quot; \u0438\u043b\u0438 &quot;-fms-extensions&quot;). \u041d\u0430\u043f\u0438\u0448\u0435\u043c \u00ab\u043a\u043b\u0430\u0441\u0441\u00bb, \u00ab\u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439\u00bb \u043e\u0442 zip compressor&#8217;a<\/p>\n<pre><code>typedef struct logging_compressor_t {   union   {     struct compressor_t;     struct compressor_t base;   };   void (*log)(struct logging_compressor_t* lc);   void *impl_; \/\/ \u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e } logging_compressor_t; <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u00ab\u0431\u0430\u0437\u043e\u0432\u043e\u043c\u0443\u00bb \u00ab\u043a\u043b\u0430\u0441\u0441\u0443\u00bb \u043a\u0430\u043a \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e  <\/p>\n<pre><code>logging_compressor_t lc; lc.compress(...) <\/code><\/pre>\n<p>  \u0442\u0430\u043a \u0438 \u0447\u0435\u0440\u0435\u0437 \u0447\u043b\u0435\u043d \u0434\u0430\u043d\u043d\u044b\u0445   <\/p>\n<pre><code>lc.base.compress(...) <\/code><\/pre>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0436\u0435 \u0434\u0430\u043d\u043d\u044b\u0439 \u00ab\u043a\u043b\u0430\u0441\u0441\u00bb \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u043d\u043e \u0432 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c \u043a\u043e\u0434\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c<\/p>\n<pre><code>work(&lc.base, uncompressed_data, compressed_data); <\/code><\/pre>\n<p>  \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0432\u043e\u0437\u0440\u0430\u0437\u0438\u0442 \u043c\u043d\u0435, \u0434\u043e\u0442\u043e\u0448\u043d\u044b\u0439 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c, \u0432 \u0442\u0430\u043a\u043e\u0439 \u0441\u0445\u0435\u043c\u0435 \u043c\u043d\u043e\u0433\u043e\u0435 \u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u043d\u0430 \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u0432\u0441\u0435 \u0438\u0441\u043f\u043e\u0440\u0442\u0438\u0442\u044c \u0432\u044b\u0437\u0432\u0430\u0432 \u00ab\u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u00bb zip \u0434\u043b\u044f rar \u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442, \u0438 \u043d\u0430\u0434\u0435\u043b\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0434\u0440\u0443\u0433\u0438\u0445 \u0433\u043b\u0443\u043f\u043e\u0441\u0442\u0435\u0439. \u041d\u043e \u0445\u043e\u0447\u0443 \u043d\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u0432\u043e-\u043f\u0435\u0440\u0432\u044b\u0445 \u0421-\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u0438 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u044b\u043c, \u0430 \u0432\u043e-\u0432\u0442\u043e\u0440\u044b\u0445 \u0446\u0435\u043b\u044c\u044e \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0435 \u0431\u044b\u043b\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u043e, \u0447\u0442\u043e \u0421 \u00ab\u043a\u0440\u0443\u0447\u0435\u00bb \u0434\u0440\u0443\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u043e\u0432, \u0430 \u043b\u0438\u0448\u044c \u0442\u043e, \u0447\u0442\u043e \u043f\u0440\u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0438 \u0432 \u0441\u0442\u0430\u0440\u043e\u043c \u0434\u043e\u0431\u0440\u043e\u043c \u0421 \u043c\u043e\u0436\u043d\u043e \u0441 \u0443\u0441\u043f\u0435\u0445\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 \u0438\u0437 \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0441\u043e\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0445 \u044f\u0437\u044b\u043a\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u0442\u0438\u043b\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \t\t\t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/205570\/\"> http:\/\/habrahabr.ru\/post\/205570\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\"> \t\t\t\u0412\u0430\u043c \u0434\u0430\u043b\u0438 \u0437\u0430\u0434\u0430\u043d\u0438\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043d\u0430 \u0421, \u0430 \u0432\u044b \u0443\u0436\u0435 \u0437\u0430\u0431\u044b\u043b\u0438 \u043a\u0430\u043a \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u0432 \u0442\u0435\u043a\u0441\u0442\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0435\u0442 \u043d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 class \u0438\u043b\u0438 virtual? \u0418\u043b\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b \u0432\u043b\u044e\u0431\u043b\u0435\u043d\u044b \u0432 \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u0443 \u0438 \u0441\u0442\u0440\u043e\u0433\u043e\u0441\u0442\u044c ANSI C, \u043d\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u0432\u0430\u043c \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u044f\u0437\u044b\u043a\u043e\u0432 \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0441\u043e\u043a\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f? \u0418\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u043d\u0430 \u0441\u0442\u0430\u0440\u044b\u0439 \u0434\u043e\u0431\u0440\u044b\u0439 \u0421 \u0441 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b? \u0412 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043f\u0440\u0438\u0435\u043c\u043e\u0432, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0430 C \u0432\u043f\u043e\u043b\u043d\u0435 \u043c\u043e\u0436\u043d\u043e \u0434\u0443\u043c\u0430\u0442\u044c \u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u043e-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-205570","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/205570","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=205570"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/205570\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=205570"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=205570"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=205570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}