Elipsis with array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • berte

    Elipsis with array

    Hello folks,

    I investigating kernel sources I coincided with this part:

    struct irq_desc irq_desc[NR_IRQS] __cacheline_ali gned_in_smp = {
    [0 ... NR_IRQS-1] = {
    .status = IRQ_DISABLED,
    .chip = &no_irq_chip ,
    .handle_irq = handle_bad_irq,
    .depth = 1,
    .lock = __SPIN_LOCK_UNL OCKED(irq_desc->lock),
    #ifdef CONFIG_SMP
    .affinity = CPU_MASK_ALL
    #endif
    }
    };

    Q1- What is this part "[0 ... NR_IRQS-1]" ?
    Q2- Elipsis using with arrays ?

    Regards.
  • Antoninus Twink

    #2
    Re: Elipsis with array

    On 13 Oct 2008 at 10:23, berte wrote:
    struct irq_desc irq_desc[NR_IRQS] __cacheline_ali gned_in_smp = {
    [0 ... NR_IRQS-1] = {
    .status = IRQ_DISABLED,
    [snip]
    >
    Q1- What is this part "[0 ... NR_IRQS-1]" ?
    Q2- Elipsis using with arrays ?
    This is a GNU extension. See
    <http://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html>

    Comment

    • Antoninus Twink

      #3
      Re: Elipsis with array

      On 13 Oct 2008 at 10:23, berte wrote:
      struct irq_desc irq_desc[NR_IRQS] __cacheline_ali gned_in_smp = {
      [0 ... NR_IRQS-1] = {
      .status = IRQ_DISABLED,
      [snip]
      >
      Q1- What is this part "[0 ... NR_IRQS-1]" ?
      Q2- Elipsis using with arrays ?
      This is a GNU extension. See
      <http://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html>

      Comment

      • Wolfgang Draxinger

        #4
        Re: Elipsis with array

        berte wrote:
        Hello folks,
        >
        I investigating kernel sources I coincided with this part:
        >
        struct irq_desc irq_desc[NR_IRQS] __cacheline_ali gned_in_smp =
        { [0 ... NR_IRQS-1] = {
        .status = IRQ_DISABLED,
        .chip = &no_irq_chip ,
        .handle_irq = handle_bad_irq,
        .depth = 1,
        .lock = __SPIN_LOCK_UNL OCKED(irq_desc->lock),
        #ifdef CONFIG_SMP
        .affinity = CPU_MASK_ALL
        #endif
        }
        };
        >
        Q1- What is this part "[0 ... NR_IRQS-1]" ?
        Q2- Elipsis using with arrays ?
        Those are GNU extensions to the GCC, to ease the static
        initialization of structures. You find them to be used
        throughout large parts of the Linux kernel sources and their use
        is highly encouraged to enhance readability.

        See the documentation here:


        Wolfgang Draxinger
        --
        E-Mail address works, Jabber: hexarith@jabber .org, ICQ: 134682867

        Comment

        • Martien Verbruggen

          #5
          Re: Elipsis with array

          On Mon, 13 Oct 2008 03:23:31 -0700 (PDT),
          berte <behzaterte@gma il.comwrote:
          Hello folks,
          >
          I investigating kernel sources I coincided with this part:
          >
          struct irq_desc irq_desc[NR_IRQS] __cacheline_ali gned_in_smp = {
          [0 ... NR_IRQS-1] = {
          That's not standard C, but a gcc extension to initialise a range of
          elements to the same value.

          Check the gcc manual, under 'C Extensions' - 'Designated Inits'.

          Martien
          --
          |
          Martien Verbruggen |
          | The gene pool could use a little chlorine.
          |

          Comment

          • berte

            #6
            Re: Elipsis with array

            On 13 Ekim, 13:52, Martien Verbruggen <m...@tradingpo st.com.auwrote:
            On Mon, 13 Oct 2008 03:23:31 -0700 (PDT),
                    berte <behzate...@gma il.comwrote:
            >
            Hello folks,
            >
            I investigating kernel sources I coincided with this part:
            >
            struct irq_desc irq_desc[NR_IRQS] __cacheline_ali gned_in_smp = {
               [0 ... NR_IRQS-1] = {
            >
            That's not standard C, but a gcc extension to initialise a range of
            elements to the same value.
            >
            Check the gcc manual, under 'C Extensions' - 'Designated Inits'.
            >
            Martien
            --
                                    |
            Martien Verbruggen      |
                                    | The gene pool could usea little chlorine.
                                    |
            Thank you all. I got it :-)

            Regards,
            berte

            Comment

            • Ben Bacarisse

              #7
              Re: Elipsis with array

              jacob navia <jacob@nospam.c omwrites:
              berte wrote:
              >>
              >I investigating kernel sources I coincided with this part:
              >>
              >struct irq_desc irq_desc[NR_IRQS] __cacheline_ali gned_in_smp = {
              > [0 ... NR_IRQS-1] = {
              > .status = IRQ_DISABLED,
              > .chip = &no_irq_chip ,
              > .handle_irq = handle_bad_irq,
              > .depth = 1,
              > .lock = __SPIN_LOCK_UNL OCKED(irq_desc->lock),
              >#ifdef CONFIG_SMP
              > .affinity = CPU_MASK_ALL
              >#endif
              > }
              >};
              >>
              >Q1- What is this part "[0 ... NR_IRQS-1]" ?
              >Q2- Elipsis using with arrays ?
              >>
              >
              This is a gnu extension. In

              you can read:
              4.20 Labeled Elements in Initializers
              <snip quote from old manual>

              By quoting such an old manual you obscure what is C99 and what is an
              extension. The newer version makes it much clearer.



              --
              Ben.

              Comment

              Working...