All of lore.kernel.org
 help / color / mirror / Atom feed
* C++ Question
@ 1999-10-21  1:40 ian reinhart geiser
  0 siblings, 0 replies; 16+ messages in thread
From: ian reinhart geiser @ 1999-10-21  1:40 UTC (permalink / raw)
  To: linuxppc-dev


I have confirmed that this works under 2.95 under RH 6.1
one ix86 so I am thinking this is a LinuxPPC problem.

I am building the gcc cross compiler for th 68HC11 using
the 2.8.1 source code and a patch supplied by my professor.

i get the following error:

gcc -c -DCROSS_COMPILE -DIN_GCC    -g  -DHAVE_CONFIG_H    -I. -I.
-I./config fol
d-const.c
fold-const.c: In function `exact_real_inverse':
fold-const.c:945: parse error before `if'
fold-const.c: At top level:
fold-const.c:945: parse error before `else'
fold-const.c:945: parse error before `.'
fold-const.c:945: parse error before `.'
fold-const.c:945: parse error before `.'
fold-const.c:959: parse error before `('
fold-const.c:960: `y' undeclared here (not in a function)
fold-const.c:960: warning: data definition has no type or storage class
fold-const.c:961: parse error before `return'
make: *** [fold-const.o] Error 1     

When I looked at the code i found the following:

exact_real_inverse (mode, r)
     enum machine_mode mode;
     REAL_VALUE_TYPE *r;
{
  union
    {
      double d;
      unsigned short i[4];
    }x, t, y;     
----SNIP----
and at 945 the following code...
941:  /* Truncate to the required mode and range-check the result.  */
942:  y.d = REAL_VALUE_TRUNCATE (mode, t.d);
943:#ifdef CHECK_FLOAT_VALUE
944:  i = 0;
945:	  if (CHECK_FLOAT_VALUE (mode, y.d, i))
946:    goto fail;
947:#endif 

why did i get an error on y.d on 945 and not 941?

any ideas?

sorry if i am missing info, i have been beating on this
for a week and it is all getting blurry...

-ian reinhart geiser


** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

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

* C question
@ 2009-10-08  2:12 Rick Brown
  2009-10-08  2:52 ` Manish Katiyar
  2009-10-08  3:02 ` mayur nande
  0 siblings, 2 replies; 16+ messages in thread
From: Rick Brown @ 2009-10-08  2:12 UTC (permalink / raw)
  To: kernelnewbies, linux-newbie

Hello list,

As far as I recall from K&R, isn't pointer arithmetic on a void
pointer banned? And any effort to do that results in an error -
because the compiler won't know by how much size to increment the
pointer for a statement like "ptr++"? But then how about this:

[rick@linux rick]$ cat t.c
#include <stdio.h>
int main()
{
    void *ptr = 0;
    printf("%d \n", ptr+1);
}
[rick@linux rick]$ gcc t.c
[rick@linux rick]$ ./a.out
1
[rick@linux rick]$

It compiles and runs fine ... !

TIA,

Rick

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ


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

* Re: C question
  2009-10-08  2:12 C question Rick Brown
@ 2009-10-08  2:52 ` Manish Katiyar
  2009-10-08  5:37   ` Kalpesh Rathod
  2009-10-08  8:48   ` Michał Nazarewicz
  2009-10-08  3:02 ` mayur nande
  1 sibling, 2 replies; 16+ messages in thread
From: Manish Katiyar @ 2009-10-08  2:52 UTC (permalink / raw)
  To: Rick Brown; +Cc: kernelnewbies, linux-newbie

On Thu, Oct 8, 2009 at 7:42 AM, Rick Brown <rick.brown.3@gmail.com> wrote:
> Hello list,
>
> As far as I recall from K&R, isn't pointer arithmetic on a void
> pointer banned? And any effort to do that results in an error -
> because the compiler won't know by how much size to increment the
> pointer for a statement like "ptr++"? But then how about this:

But in the program, you aren't actually trying to dereference the
value. Just adding means it becomes normal arithmetic and that is why
you get result as 1. You will see the error if you try to dereference
it.

/tmp> gcc a.c
a.c: In function ‘main’:
a.c:5: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘void *’
a.c:6: warning: dereferencing ‘void *’ pointer
a.c:6: error: invalid use of void expression
/tmp> cat a.c
#include <stdio.h>
int main()
{
   void *ptr = 0;
   printf("%d \n", ptr+1);
   printf("%d \n", *(ptr+1));
}


>
> [rick@linux rick]$ cat t.c
> #include <stdio.h>
> int main()
> {
>    void *ptr = 0;
>    printf("%d \n", ptr+1);
> }
> [rick@linux rick]$ gcc t.c
> [rick@linux rick]$ ./a.out
> 1
> [rick@linux rick]$
>
> It compiles and runs fine ... !
>
> TIA,
>
> Rick
>
> --
> To unsubscribe from this list: send an email with
> "unsubscribe kernelnewbies" to ecartis@nl.linux.org
> Please read the FAQ at http://kernelnewbies.org/FAQ
>
>



-- 
Thanks -
Manish
==================================
[$\*.^ -- I miss being one of them
==================================

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ


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

* Re: C question
  2009-10-08  2:12 C question Rick Brown
  2009-10-08  2:52 ` Manish Katiyar
@ 2009-10-08  3:02 ` mayur nande
  2009-10-08  5:43   ` sandeep lahane
  1 sibling, 1 reply; 16+ messages in thread
From: mayur nande @ 2009-10-08  3:02 UTC (permalink / raw)
  To: Rick Brown; +Cc: kernelnewbies, linux-newbie

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

Hi Rick,

Some days ago i had the same question in my mind. While going through "The
Linux Kernel Architecture" book (by Wolfgang Mauerer), i got the answer:

The GNU compiler supports arithmetic with void pointers as well as function
pointers. The increment step is 1 byte. These are used by the kernel at
various points.

Have fun.

Regards
Mayur

On Thu, Oct 8, 2009 at 7:42 AM, Rick Brown <rick.brown.3@gmail.com> wrote:

> Hello list,
>
> As far as I recall from K&R, isn't pointer arithmetic on a void
> pointer banned? And any effort to do that results in an error -
> because the compiler won't know by how much size to increment the
> pointer for a statement like "ptr++"? But then how about this:
>
> [rick@linux rick]$ cat t.c
> #include <stdio.h>
> int main()
> {
>    void *ptr = 0;
>    printf("%d \n", ptr+1);
> }
> [rick@linux rick]$ gcc t.c
> [rick@linux rick]$ ./a.out
> 1
> [rick@linux rick]$
>
> It compiles and runs fine ... !
>
> TIA,
>
> Rick
>
> --
> To unsubscribe from this list: send an email with
> "unsubscribe kernelnewbies" to ecartis@nl.linux.org
> Please read the FAQ at http://kernelnewbies.org/FAQ
>
>

[-- Attachment #2: Type: text/html, Size: 1715 bytes --]

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

* Re: C question
  2009-10-08  2:52 ` Manish Katiyar
@ 2009-10-08  5:37   ` Kalpesh Rathod
  2009-10-08  8:48   ` Michał Nazarewicz
  1 sibling, 0 replies; 16+ messages in thread
From: Kalpesh Rathod @ 2009-10-08  5:37 UTC (permalink / raw)
  To: Rick Brown; +Cc: kernelnewbies, linux-newbie

Hi Rick,

gcc can warn about void pointer increment if you use compiler option
-Wpointer-arith

==
Kalpesh

On Thu, Oct 8, 2009 at 8:22 AM, Manish Katiyar <mkatiyar@gmail.com> wrote:
> On Thu, Oct 8, 2009 at 7:42 AM, Rick Brown <rick.brown.3@gmail.com> wrote:
>> Hello list,
>>
>> As far as I recall from K&R, isn't pointer arithmetic on a void
>> pointer banned? And any effort to do that results in an error -
>> because the compiler won't know by how much size to increment the
>> pointer for a statement like "ptr++"? But then how about this:
>
> But in the program, you aren't actually trying to dereference the
> value. Just adding means it becomes normal arithmetic and that is why
> you get result as 1. You will see the error if you try to dereference
> it.
>
> /tmp> gcc a.c
> a.c: In function ‘main’:
> a.c:5: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘void *’
> a.c:6: warning: dereferencing ‘void *’ pointer
> a.c:6: error: invalid use of void expression
> /tmp> cat a.c
> #include <stdio.h>
> int main()
> {
>   void *ptr = 0;
>   printf("%d \n", ptr+1);
>   printf("%d \n", *(ptr+1));
> }
>
>
>>
>> [rick@linux rick]$ cat t.c
>> #include <stdio.h>
>> int main()
>> {
>>    void *ptr = 0;
>>    printf("%d \n", ptr+1);
>> }
>> [rick@linux rick]$ gcc t.c
>> [rick@linux rick]$ ./a.out
>> 1
>> [rick@linux rick]$
>>
>> It compiles and runs fine ... !
>>
>> TIA,
>>
>> Rick
>>
>> --
>> To unsubscribe from this list: send an email with
>> "unsubscribe kernelnewbies" to ecartis@nl.linux.org
>> Please read the FAQ at http://kernelnewbies.org/FAQ
>>
>>
>
>
>
> --
> Thanks -
> Manish
> ==================================
> [$\*.^ -- I miss being one of them
> ==================================
>
> --
> To unsubscribe from this list: send an email with
> "unsubscribe kernelnewbies" to ecartis@nl.linux.org
> Please read the FAQ at http://kernelnewbies.org/FAQ
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

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

* Re: C question
  2009-10-08  3:02 ` mayur nande
@ 2009-10-08  5:43   ` sandeep lahane
  0 siblings, 0 replies; 16+ messages in thread
From: sandeep lahane @ 2009-10-08  5:43 UTC (permalink / raw)
  To: mayur nande; +Cc: Rick Brown, kernelnewbies, linux-newbie

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

On Thu, Oct 8, 2009 at 8:32 AM, mayur nande <mayur.nan@gmail.com> wrote:

> Hi Rick,
>
> Some days ago i had the same question in my mind. While going through "The
> Linux Kernel Architecture" book (by Wolfgang Mauerer), i got the answer:
>
> The GNU compiler supports arithmetic with void pointers as well as function
> pointers. The increment step is 1 byte. These are used by the kernel at
> various points.
>
> Have fun.
>
> Regards
> Mayur
>
> On Thu, Oct 8, 2009 at 7:42 AM, Rick Brown <rick.brown.3@gmail.com> wrote:
>
>> Hello list,
>>
>> As far as I recall from K&R, isn't pointer arithmetic on a void
>> pointer banned? And any effort to do that results in an error -
>> because the compiler won't know by how much size to increment the
>> pointer for a statement like "ptr++"? But then how about this:
>>
>> [rick@linux rick]$ cat t.c
>> #include <stdio.h>
>> int main()
>> {
>>    void *ptr = 0;
>>    printf("%d \n", ptr+1);
>> }
>> [rick@linux rick]$ gcc t.c
>> [rick@linux rick]$ ./a.out
>> 1
>> [rick@linux rick]$
>>
>> It compiles and runs fine ... !
>>
>> TIA,
>>
>> Rick
>>
>> --
>> To unsubscribe from this list: send an email with
>> "unsubscribe kernelnewbies" to ecartis@nl.linux.org
>> Please read the FAQ at http://kernelnewbies.org/FAQ
>>
>>
>
Arithmetic on void and function pointers is part of GNU C extensions, C
standard
does not support it (size of void and functions is taken as 1). There are
many such
GNU extensions which are used in kernel. One way to figure out which all
extensions
are used is by providing -pedantic flag, this will emit warning for such
usage.

I think many of these extensions have became part of C99 standard already.


Regards,
Sandeep.

[-- Attachment #2: Type: text/html, Size: 2678 bytes --]

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

* Re: C question
  2009-10-08  2:52 ` Manish Katiyar
  2009-10-08  5:37   ` Kalpesh Rathod
@ 2009-10-08  8:48   ` Michał Nazarewicz
  1 sibling, 0 replies; 16+ messages in thread
From: Michał Nazarewicz @ 2009-10-08  8:48 UTC (permalink / raw)
  To: Manish Katiyar, Rick Brown; +Cc: kernelnewbies, linux-newbie

> On Thu, Oct 8, 2009 at 7:42 AM, Rick Brown <rick.brown.3@gmail.com> wrote:
>> As far as I recall from K&R, isn't pointer arithmetic on a void
>> pointer banned? And any effort to do that results in an error -
>> because the compiler won't know by how much size to increment the
>> pointer for a statement like "ptr++"?

On Thu, 08 Oct 2009 04:52:31 +0200, Manish Katiyar <mkatiyar@gmail.com> wrote:
> But in the program, you aren't actually trying to dereference the
> value. Just adding means it becomes normal arithmetic and that is why
> you get result as 1. You will see the error if you try to dereference
> it.

This comment is a bit misleading.  The standard does not define behaviour
of pointer arithmetic on pointer to void.  What one need to realise is that
undefined behaviour means compiler's documentation may well define how such
a construct is evaluated and gcc (with proper options) decides to treat
pointer to void as if sizeof(void) == 1.

So the thing it's true pointer arithmetic on a pointer to void is undefined
behaviour as far as C standard is concerned however because Linux is
compiled with gcc kernel's developers tend to make use of gcc's extensions
and one of it is arithmetic on a pointer to void.

-- 
Best regards,                                           _     _
  .o. | Liege of Serenely Enlightened Majesty of       o' \,=./ `o
  ..o | Computer Science,  Michał "mina86" Nazarewicz     (o o)
  ooo +---<mina86@mina86.com>---<mina86@jabber.org>---ooO--(_)--Ooo--

--
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

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

* C Question
@ 2010-05-25 10:08 Randi Botse
  2010-05-25 10:19 ` Xiaotian Feng
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Randi Botse @ 2010-05-25 10:08 UTC (permalink / raw)
  To: linux-c-programming

Hi All,

Im looking at lscpu.c shipped by util-linux-ng-2.17, can you explain
me how the *vir_types[] declared, is this valid C declaration?

/* virtualization types */
enum {
	VIRT_NONE	= 0,
	VIRT_PARA,
	VIRT_FULL
};
const char *virt_types[] = {
	[VIRT_NONE]	= N_("none"),
	[VIRT_PARA]	= N_("para"),
	[VIRT_FULL]	= N_("full")
};

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

* Re: C Question
  2010-05-25 10:08 C Question Randi Botse
@ 2010-05-25 10:19 ` Xiaotian Feng
       [not found]   ` <AANLkTinTu94E7guvzjySpGjht2Hjw4aop4vRIVpHo9UL@mail.gmail.com>
  2010-05-25 11:18 ` Uriel Corfa
  2010-05-25 11:41 ` Michal Nazarewicz
  2 siblings, 1 reply; 16+ messages in thread
From: Xiaotian Feng @ 2010-05-25 10:19 UTC (permalink / raw)
  To: Randi Botse; +Cc: linux-c-programming

On Tue, May 25, 2010 at 6:08 PM, Randi Botse <nightdecoder@gmail.com> wrote:
> Hi All,
>
> Im looking at lscpu.c shipped by util-linux-ng-2.17, can you explain
> me how the *vir_types[] declared, is this valid C declaration?
>

N_(blah) must be defined in some include files

> /* virtualization types */
> enum {
>        VIRT_NONE       = 0,
>        VIRT_PARA,
>        VIRT_FULL
> };
> const char *virt_types[] = {
>        [VIRT_NONE]     = N_("none"),
>        [VIRT_PARA]     = N_("para"),
>        [VIRT_FULL]     = N_("full")
> };
> --
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: C Question
       [not found]   ` <AANLkTinTu94E7guvzjySpGjht2Hjw4aop4vRIVpHo9UL@mail.gmail.com>
@ 2010-05-25 10:49     ` Randi Botse
  0 siblings, 0 replies; 16+ messages in thread
From: Randi Botse @ 2010-05-25 10:49 UTC (permalink / raw)
  To: Guillaume Leconte; +Cc: linux-c-programming

Yes, that's i was talking about, i got the idea, gcc even let me
declared "unordered" subobject index like this..

const char *my_strings[] = {
            [0] = "string1",
            [2] = "string2",
            [1] = "string3",
            etc...
}

Actually, this is my first time seeing codes like this, it was strange
for me :p, many thanks for let me know!

- Randi,


On Tue, May 25, 2010 at 5:24 PM, Guillaume Leconte
<guillaume.leconte@gmail.com> wrote:

> I think he is talking about the [VIRT_NONE] = ... style, which is C99.
>
>>
>> > /* virtualization types */
>> > enum {
>> >        VIRT_NONE       = 0,
>> >        VIRT_PARA,
>> >        VIRT_FULL
>> > };
>> > const char *virt_types[] = {
>> >        [VIRT_NONE]     = N_("none"),
>> >        [VIRT_PARA]     = N_("para"),
>> >        [VIRT_FULL]     = N_("full")
>> > };
>
> It is equivalent to:
>
> const char *virt_types[3];
>
> virt_types[VIRT_NONE] = N_("none");
> virt_types[VIRT_PARA] = N_("para");
> virt_types[VIRT_FULL] = N_("full");
>
>
>>
>> > --
>> > To unsubscribe from this list: send the line "unsubscribe
>> > linux-c-programming" in
>> > the body of a message to majordomo@vger.kernel.org
>> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
>> >
>> --
>> To unsubscribe from this list: send the line "unsubscribe
>> linux-c-programming" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
>
>
> --
> « I've seen things you people wouldn't believe.  Attack ships on fire
> off the shoulder of Orion.  I watched C-beams glitter in the dark near
> the Tanhauser gate.  All those moments will be lost in time like tears
> in rain.  Time to die. »
>
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: C Question
  2010-05-25 10:08 C Question Randi Botse
  2010-05-25 10:19 ` Xiaotian Feng
@ 2010-05-25 11:18 ` Uriel Corfa
  2010-05-25 11:41 ` Michal Nazarewicz
  2 siblings, 0 replies; 16+ messages in thread
From: Uriel Corfa @ 2010-05-25 11:18 UTC (permalink / raw)
  To: Randi Botse; +Cc: linux-c-programming

That's "designated initializers". It's C99.

It allows you to initialize some members to a specific value without
specifying the default value manually for the other ones.

Refs :
http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf  chapter 6.7.8.6
http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=/com.ibm.xlcpp8a.doc/language/ref/designators.htm

On Tue, May 25, 2010 at 12:08 PM, Randi Botse <nightdecoder@gmail.com> wrote:
> Hi All,
>
> Im looking at lscpu.c shipped by util-linux-ng-2.17, can you explain
> me how the *vir_types[] declared, is this valid C declaration?
>
> /* virtualization types */
> enum {
>        VIRT_NONE       = 0,
>        VIRT_PARA,
>        VIRT_FULL
> };
> const char *virt_types[] = {
>        [VIRT_NONE]     = N_("none"),
>        [VIRT_PARA]     = N_("para"),
>        [VIRT_FULL]     = N_("full")
> };
> --
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>



-- 
Uriel Corfa
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: C Question
  2010-05-25 10:08 C Question Randi Botse
  2010-05-25 10:19 ` Xiaotian Feng
  2010-05-25 11:18 ` Uriel Corfa
@ 2010-05-25 11:41 ` Michal Nazarewicz
  2010-05-30 10:41   ` Randi Botse
  2 siblings, 1 reply; 16+ messages in thread
From: Michal Nazarewicz @ 2010-05-25 11:41 UTC (permalink / raw)
  To: Randi Botse; +Cc: linux-c-programming

Randi Botse <nightdecoder@gmail.com> writes:

> Hi All,
>
> Im looking at lscpu.c shipped by util-linux-ng-2.17, can you explain
> me how the *vir_types[] declared, is this valid C declaration?
>
> /* virtualization types */
> enum {
> 	VIRT_NONE	= 0,
> 	VIRT_PARA,
> 	VIRT_FULL
> };
> const char *virt_types[] = {
> 	[VIRT_NONE]	= N_("none"),
> 	[VIRT_PARA]	= N_("para"),
> 	[VIRT_FULL]	= N_("full")
> };

As Xiaotian Feng said, N_(x) must be defined somewhere and additionally
to this this definition uses a new syntax where you can specify indexes
of elements you want to set value to, ie. the above is the same as:

const char *virt_types[] = {
	[0]	= N_("none"),
	[1]	= N_("para"),
	[2]	= N_("full")
};

which in turn is the same as:

const char *virt_types[] = {
	N_("none"),
	N_("para"),
	N_("full")
};

The advantage of the new syntax is that you can specify values in any
order and omit some.

-- 
Best regards,                                         _     _
 .o. | Liege of Serenly Enlightened Majesty of      o' \,=./ `o
 ..o | Computer Science,  Michal "mina86" Nazarewicz   (o o)
 ooo +--<mina86-tlen.pl>--<jid:mina86-jabber.org>--ooO--(_)--Ooo--

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

* Re: C Question
  2010-05-25 11:41 ` Michal Nazarewicz
@ 2010-05-30 10:41   ` Randi Botse
  2010-05-30 12:38     ` Michal Nazarewicz
  0 siblings, 1 reply; 16+ messages in thread
From: Randi Botse @ 2010-05-30 10:41 UTC (permalink / raw)
  To: Michal Nazarewicz; +Cc: linux-c-programming

Yes, the N_(x) macro used for localization that i discard in my question.

Sorry but, i just having another question, consider this code:

const char *my_strings[] = {
    [0] = "index0",
    [4] = "index4",
    [6] = "index6"
};

How many pointer to char that my_string array holds now? is that 3?
where are index [1], [2], [3], and [5] ?

2010/5/25 Michal Nazarewicz <mina86@tlen.pl>:
>
> As Xiaotian Feng said, N_(x) must be defined somewhere and additionally
> to this this definition uses a new syntax where you can specify indexes
> of elements you want to set value to, ie. the above is the same as:
>
> const char *virt_types[] = {
>        [0]     = N_("none"),
>        [1]     = N_("para"),
>        [2]     = N_("full")
> };
>
> which in turn is the same as:
>
> const char *virt_types[] = {
>        N_("none"),
>        N_("para"),
>        N_("full")
> };
>
> The advantage of the new syntax is that you can specify values in any
> order and omit some.
>
> --
> Best regards,                                         _     _
>  .o. | Liege of Serenly Enlightened Majesty of      o' \,=./ `o
>  ..o | Computer Science,  Michal "mina86" Nazarewicz   (o o)
>  ooo +--<mina86-tlen.pl>--<jid:mina86-jabber.org>--ooO--(_)--Ooo--
>
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: C Question
  2010-05-30 10:41   ` Randi Botse
@ 2010-05-30 12:38     ` Michal Nazarewicz
  2010-06-01 11:59       ` Randi Botse
  0 siblings, 1 reply; 16+ messages in thread
From: Michal Nazarewicz @ 2010-05-30 12:38 UTC (permalink / raw)
  To: Randi Botse; +Cc: linux-c-programming

Randi Botse <nightdecoder@gmail.com> writes:
> Yes, the N_(x) macro used for localization that i discard in my question.
>
> Sorry but, i just having another question, consider this code:
>
> const char *my_strings[] = {
>     [0] = "index0",
>     [4] = "index4",
>     [6] = "index6"
> };

NULLs will be written at indexes 1, 2, 3 and 5.  There will be total of
7 pointers (the last one will point to "index6").

-- 
Best regards,                                         _     _
 .o. | Liege of Serenly Enlightened Majesty of      o' \,=./ `o
 ..o | Computer Science,  Michal "mina86" Nazarewicz   (o o)
 ooo +--<mina86-tlen.pl>--<jid:mina86-jabber.org>--ooO--(_)--Ooo--

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

* Re: C Question
  2010-05-30 12:38     ` Michal Nazarewicz
@ 2010-06-01 11:59       ` Randi Botse
  2010-06-01 13:18         ` Glynn Clements
  0 siblings, 1 reply; 16+ messages in thread
From: Randi Botse @ 2010-06-01 11:59 UTC (permalink / raw)
  To: Michal Nazarewicz; +Cc: linux-c-programming

That's clear now, i was though the 'unindexed' strings (in this case
index 1, 2, 3, and 5) remains unintialized (not initialized to NULL).

Thanks very much.

Randi,

2010/5/30 Michal Nazarewicz <mina86@tlen.pl>:
> Randi Botse <nightdecoder@gmail.com> writes:
>> Yes, the N_(x) macro used for localization that i discard in my question.
>>
>> Sorry but, i just having another question, consider this code:
>>
>> const char *my_strings[] = {
>>     [0] = "index0",
>>     [4] = "index4",
>>     [6] = "index6"
>> };
>
> NULLs will be written at indexes 1, 2, 3 and 5.  There will be total of
> 7 pointers (the last one will point to "index6").
>
> --
> Best regards,                                         _     _
>  .o. | Liege of Serenly Enlightened Majesty of      o' \,=./ `o
>  ..o | Computer Science,  Michal "mina86" Nazarewicz   (o o)
>  ooo +--<mina86-tlen.pl>--<jid:mina86-jabber.org>--ooO--(_)--Ooo--
>
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: C Question
  2010-06-01 11:59       ` Randi Botse
@ 2010-06-01 13:18         ` Glynn Clements
  0 siblings, 0 replies; 16+ messages in thread
From: Glynn Clements @ 2010-06-01 13:18 UTC (permalink / raw)
  To: Randi Botse; +Cc: Michal Nazarewicz, linux-c-programming


Randi Botse wrote:

> >> Sorry but, i just having another question, consider this code:
> >>
> >> const char *my_strings[] = {
> >>     [0] = "index0",
> >>     [4] = "index4",
> >>     [6] = "index6"
> >> };
> >
> > NULLs will be written at indexes 1, 2, 3 and 5.  There will be total of
> > 7 pointers (the last one will point to "index6").
> 
> That's clear now, i was though the 'unindexed' strings (in this case
> index 1, 2, 3, and 5) remains unintialized (not initialized to NULL).

If you specify an initialiser, the entire object is initialised. If
you specify an incomplete initialiser, the unspecified elements are
initialised to the appropriate zero value (0, 0.0, '\0', NULL, etc).

The C99 standard says (6.7.8p21):

       [#21]  If  there  are fewer initializers in a brace-enclosed
       list than there are elements or members of an aggregate,  or
       fewer  characters  in a string literal used to initialize an
       array of known size than there are elements  in  the  array,
       the   remainder   of  the  aggregate  shall  be  initialized
       implicitly the same as  objects  that  have  static  storage
       duration.

This applies to both traditional C89 sequential initialisers and C99
designated initialisers. It allows you to initialise large arrays or
structures without having to specify every element; e.g.:

	int array[1000] = {0};
	struct foo f = {0};

will initialise the entire array or structure to zero.

-- 
Glynn Clements <glynn@gclements.plus.com>
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2010-06-01 13:18 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-08  2:12 C question Rick Brown
2009-10-08  2:52 ` Manish Katiyar
2009-10-08  5:37   ` Kalpesh Rathod
2009-10-08  8:48   ` Michał Nazarewicz
2009-10-08  3:02 ` mayur nande
2009-10-08  5:43   ` sandeep lahane
  -- strict thread matches above, loose matches on Subject: below --
2010-05-25 10:08 C Question Randi Botse
2010-05-25 10:19 ` Xiaotian Feng
     [not found]   ` <AANLkTinTu94E7guvzjySpGjht2Hjw4aop4vRIVpHo9UL@mail.gmail.com>
2010-05-25 10:49     ` Randi Botse
2010-05-25 11:18 ` Uriel Corfa
2010-05-25 11:41 ` Michal Nazarewicz
2010-05-30 10:41   ` Randi Botse
2010-05-30 12:38     ` Michal Nazarewicz
2010-06-01 11:59       ` Randi Botse
2010-06-01 13:18         ` Glynn Clements
1999-10-21  1:40 C++ Question ian reinhart geiser

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.