Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9178285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:30:57+00:00 2026-06-17T17:30:57+00:00

I was examining some code on github https://github.com/umlaeute/v4l2loopback/blob/master/v4l2loopback.c and came across this line, which

  • 0

I was examining some code on github https://github.com/umlaeute/v4l2loopback/blob/master/v4l2loopback.c and came across this line, which baffles me. Is this some incredibly cool kernel macro or gcc feature that I don’t know about? What does the = -1 do?

static int video_nr[MAX_DEVICES] = { [0 ... (MAX_DEVICES-1)] = -1 };
module_param_array(video_nr, int, NULL, 0444);
MODULE_PARM_DESC(video_nr, "video device numbers (-1=auto, 0=/dev/video0, etc.)");

The line in question is the first, the next two given for context (this is creating a cmdline-specifiable parameter using a kernel macro http://lxr.free-electrons.com/source/include/linux/moduleparam.h#L103 )

Anyway, what is going on with the array initialization? How does that syntax work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T17:30:58+00:00Added an answer on June 17, 2026 at 5:30 pm

    You’ve found an example of designated initializers. C99 & C11 don’t go quite as far as your example, but they have some pretty flexible support for this kind of behaviour. Your specific example (using the ...) is a GCC extension. From the link:

    To initialize a range of elements to the same value, write [first ... last] = value. This is a GNU extension. For example,

    int widths[] = { [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 };
    

    So that means your example is creating an array of size MAX_DEVICES and initializing every element in that array to -1.

    For reference, the only standard-supported behaviour is to assign specific indices, rather than ranges:

    [constant-expression] = initializer-value

    There is a more complicated example in my copy of the spec:

    int a[MAX] = {
                1, 3, 5, 7, 9, [MAX-5] = 8, 6, 4, 2, 0
    };
    

    Which initializes the first five and last five elements of the array to explicit values. The middle values (if any) would be 0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was examining one of my client's code and came across this. $(document).ready(function() {
I'm relatively new to WPF. I'm examining some code that looks like this: private
Is there a secure alternative to mkdir() for C? I am examining some code
For some reason, I'm getting an UnsupportedOpeationException with the following code. Examining it in
I found a snippet similar to this in some (C++) code I'm preparing for
I'm examing some code and I'm found this bellow snippet of code and I
When examining some legacy Fortran code, I've found a subroutine declaration that is the
I've been examining some PHP code today and I've noticed the usage of do-while
I've been examining the code of CodeIgniter and CakePHP and I noticed that some
I'm attempting to replace some legacy DefineDosDevice userspace code (which doesn't work on Vista

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.