Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Re: Handling 'i...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 17 of 17 Topic 26103 of 26977
Post > Topic >>

Re: Handling 'initializer element not constant' error

by Szabolcs Borsanyi <borsanyi@[EMAIL PROTECTED] > May 9, 2008 at 02:32 AM

> Assuming the OP can change the code of the library, he could
> initialise yyerfp to NULL and replace all the uses of it with
>
>    (yyerfp ? yyerfp : stdout)
>
> It's a pity there isn't a standard way to get initialisation code run.
>
> -- Richard

I'd mention here a few more poins:
- <OFF>The OP want's to initialise his shared library
       (although he could avoid it with a different design). [he can
be she]
       This is usally possible on a decent operating system by
defining
       a function with a magic name.
  </OFF>
- Global objects are not quite unusual animals (especially if they are
constant)
  and one can design them using e.g. a variant of the singleton
pattern.
  In C that would be to define a pointer-to-function, and one can
indeed initialise that
  to an other function. In this case:

  FILE *yyerrf_default() { return stdout; }
  static FILE *yyerrf_ptr;
  FILE *yyerrf_user() { return yyerrf_ptr; }
  FILE *(*yyerrf)()=yyerrf_default;
  void yyerrf_set(FILE *F) { yyerrf_ptr=F; yyerrf=yyerrf_user; }
  #define yyerrf yyerrf() // protected // don't yell // is legal in
c99
  #define yyerrf_ptr      // protected

  (This is a slightly overcomplicated singleton, but of some
unjustified reasons I avoid conditionals.)

Szabolcs
 




 17 Posts in Topic:
Handling 'initializer element not constant' error
Gowtham <gowthamgowtha  2008-05-07 07:14:35 
Re: Handling 'initializer element not constant' error
viza <tom.viza@[EMAIL   2008-05-07 07:43:00 
Re: Handling 'initializer element not constant' error
Willem <willem@[EMAIL   2008-05-07 15:20:02 
Re: Handling 'initializer element not constant' error
richard@[EMAIL PROTECTED]  2008-05-07 17:01:29 
Re: Handling 'initializer element not constant' error
vippstar@[EMAIL PROTECTED  2008-05-07 10:29:14 
Re: Handling 'initializer element not constant' error
richard@[EMAIL PROTECTED]  2008-05-07 19:21:06 
Re: Handling 'initializer element not constant' error
Keith Thompson <kst-u@  2008-05-07 13:38:56 
Re: Handling 'initializer element not constant' error
vippstar@[EMAIL PROTECTED  2008-05-07 10:31:30 
Re: Handling 'initializer element not constant' error
vippstar@[EMAIL PROTECTED  2008-05-07 13:49:08 
Re: Handling 'initializer element not constant' error
richard@[EMAIL PROTECTED]  2008-05-07 22:29:06 
Re: Handling 'initializer element not constant' error
Ben Pfaff <blp@[EMAIL   2008-05-07 15:30:43 
Re: Handling 'initializer element not constant' error
richard@[EMAIL PROTECTED]  2008-05-07 22:40:52 
Re: Handling 'initializer element not constant' error
Ben Pfaff <blp@[EMAIL   2008-05-07 15:46:39 
Re: Handling 'initializer element not constant' error
dj3vande@[EMAIL PROTECTED  2008-05-07 22:44:24 
Re: Handling 'initializer element not constant' error
Flash Gordon <spam@[EM  2008-05-08 06:56:18 
Re: Handling 'initializer element not constant' error
Peter Nilsson <airia@[  2008-05-07 15:20:10 
Re: Handling 'initializer element not constant' error
Szabolcs Borsanyi <bor  2008-05-09 02:32:49 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 3:53:34 CDT 2008.