ALT Linux Team development discussions
 help / color / mirror / Atom feed
* [devel] union in C99
@ 2008-09-23 16:22 Led
  2008-09-23 16:26 ` Damir Shayhutdinov
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Led @ 2008-09-23 16:22 UTC (permalink / raw)
  To: ALT Linux Team development discussions

потребовалось сделать что-то типа такого:
-    int         i_bframe_adaptive;
+    union {
+        int         i_bframe_adaptive;
+        int         b_bframe_adaptive __attribute__((__deprecated__));
+    };

это поля structx 264_param_t . Но при -std=c99 получаем:
libx264.c:165: error: 'x264_param_t' has no member named 'i_bframe_adaptive'

Как это сейчас правильно реализуется?

-- 
Led

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [devel] union in C99
  2008-09-23 16:22 [devel] union in C99 Led
@ 2008-09-23 16:26 ` Damir Shayhutdinov
  2008-09-23 16:37   ` Led
    2008-09-23 18:22 ` Kirill A. Shutemov
  2 siblings, 1 reply; 6+ messages in thread
From: Damir Shayhutdinov @ 2008-09-23 16:26 UTC (permalink / raw)
  To: ALT Linux Team development discussions

> потребовалось сделать что-то типа такого:
> -    int         i_bframe_adaptive;
> +    union {
> +        int         i_bframe_adaptive;
> +        int         b_bframe_adaptive __attribute__((__deprecated__));
> +    };
>
> это поля structx 264_param_t . Но при -std=c99 получаем:
> libx264.c:165: error: 'x264_param_t' has no member named 'i_bframe_adaptive'
>
> Как это сейчас правильно реализуется?

То, что ты хочешь сделать - называется anonymous union

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [devel] union in C99
  2008-09-23 16:26 ` Damir Shayhutdinov
@ 2008-09-23 16:37   ` Led
  0 siblings, 0 replies; 6+ messages in thread
From: Led @ 2008-09-23 16:37 UTC (permalink / raw)
  To: ALT Linux Team development discussions

On Tuesday, 23 September 2008 19:26:24 Damir Shayhutdinov wrote:
> > потребовалось сделать что-то типа такого:
> > -    int         i_bframe_adaptive;
> > +    union {
> > +        int         i_bframe_adaptive;
> > +        int         b_bframe_adaptive __attribute__((__deprecated__));
> > +    };
> >
> > это поля structx 264_param_t . Но при -std=c99 получаем:
> > libx264.c:165: error: 'x264_param_t' has no member named
> > 'i_bframe_adaptive'
> >
> > Как это сейчас правильно реализуется?
>
> То, что ты хочешь сделать - называется anonymous union

Да, это я знаю. Но, похоже, в C99 это не допускается. Нашёл, что для gcc это 
обходится путём добавления __extension__ перед union. Может есть более 
корректный и переносимый способ реализации подобного?

-- 
Led

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [devel] union in C99
  @ 2008-09-23 18:19   ` Led
  0 siblings, 0 replies; 6+ messages in thread
From: Led @ 2008-09-23 18:19 UTC (permalink / raw)
  To: ALT Linux Team development discussions

On Tuesday, 23 September 2008 20:13:37 Konstantin Pavlov wrote:
> 2008/9/23 Led <ledest@gmail.com>
>
> > потребовалось сделать что-то типа такого:
> > -    int         i_bframe_adaptive;
> > +    union {
> > +        int         i_bframe_adaptive;
> > +        int         b_bframe_adaptive __attribute__((__deprecated__));
> > +    };
> >
> > это поля structx 264_param_t . Но при -std=c99 получаем:
> > libx264.c:165: error: 'x264_param_t' has no member named
> > 'i_bframe_adaptive'
>
> Мне кажется, легче запатчить клиентов libx264, чем менять ее API и дальше.

Запатчить надо, конечно. Но компат-хук я пока сделаю - при сборке warning про 
deprecated будет (если мейнтейнеры, конечно, обращают внимание на warning'и).

-- 
Led

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [devel] union in C99
  2008-09-23 16:22 [devel] union in C99 Led
  2008-09-23 16:26 ` Damir Shayhutdinov
  @ 2008-09-23 18:22 ` Kirill A. Shutemov
  2008-09-23 18:32   ` Led
  2 siblings, 1 reply; 6+ messages in thread
From: Kirill A. Shutemov @ 2008-09-23 18:22 UTC (permalink / raw)
  To: ALT Linux Team development discussions

[-- Attachment #1: Type: text/plain, Size: 1007 bytes --]

On Tue, Sep 23, 2008 at 07:22:41PM +0300, Led wrote:
> потребовалось сделать что-то типа такого:
> -    int         i_bframe_adaptive;
> +    union {
> +        int         i_bframe_adaptive;
> +        int         b_bframe_adaptive __attribute__((__deprecated__));
> +    };
> 
> это поля structx 264_param_t . Но при -std=c99 получаем:
> libx264.c:165: error: 'x264_param_t' has no member named 'i_bframe_adaptive'
> 
> Как это сейчас правильно реализуется?

Как вариант, можно попробовать что-то типа такого:

-    int         i_bframe_adaptive;
+#define i_bframe_adaptive bframe_adaptive.i
+#define i_bframe_adaptive bframe_adaptive.b
+    union {
+        int         i;
+        int         b __attribute__((__deprecated__));
+    } bframe_adaptive;

-- 
Regards,  Kirill A. Shutemov
 + Belarus, Minsk
 + ALT Linux Team, http://www.altlinux.com/

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [devel] union in C99
  2008-09-23 18:22 ` Kirill A. Shutemov
@ 2008-09-23 18:32   ` Led
  0 siblings, 0 replies; 6+ messages in thread
From: Led @ 2008-09-23 18:32 UTC (permalink / raw)
  To: ALT Linux Team development discussions

On Tuesday, 23 September 2008 21:22:47 Kirill A. Shutemov wrote:
> On Tue, Sep 23, 2008 at 07:22:41PM +0300, Led wrote:
> > потребовалось сделать что-то типа такого:
> > -    int         i_bframe_adaptive;
> > +    union {
> > +        int         i_bframe_adaptive;
> > +        int         b_bframe_adaptive __attribute__((__deprecated__));
> > +    };
> >
> > это поля structx 264_param_t . Но при -std=c99 получаем:
> > libx264.c:165: error: 'x264_param_t' has no member named
> > 'i_bframe_adaptive'
> >
> > Как это сейчас правильно реализуется?
>
> Как вариант, можно попробовать что-то типа такого:
>
> -    int         i_bframe_adaptive;
> +#define i_bframe_adaptive bframe_adaptive.i
> +#define i_bframe_adaptive bframe_adaptive.b
> +    union {
> +        int         i;
> +        int         b __attribute__((__deprecated__));
> +    } bframe_adaptive;

Спасибо. Да, такой вариант я тоже рассматривал, но с define'ами не очень 
красиво получается - в этом случае будет тупо подменяться все 
i_bframe_adaptive/b_bframe_adaptive, даже если это не поля структуры 
x264_param_t. Пока остановился на варианте:
+#ifdef __GNUC__
+    __extension__ union {
+        int         i_bframe_adaptive;
+        int         b_bframe_adaptive __attribute__((__deprecated__));
+    };
+#else
     int         i_bframe_adaptive;
+#endif

-- 
Led

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-09-23 18:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-23 16:22 [devel] union in C99 Led
2008-09-23 16:26 ` Damir Shayhutdinov
2008-09-23 16:37   ` Led
2008-09-23 18:19   ` Led
2008-09-23 18:22 ` Kirill A. Shutemov
2008-09-23 18:32   ` Led

ALT Linux Team development discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/devel/0 devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 devel devel/ http://lore.altlinux.org/devel \
		devel@altlinux.org devel@altlinux.ru devel@lists.altlinux.org devel@lists.altlinux.ru devel@linux.iplabs.ru mandrake-russian@linuxteam.iplabs.ru sisyphus@linuxteam.iplabs.ru
	public-inbox-index devel

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git