Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #108379

Re: Why does 'static' cause an error ?

Path csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: Why does 'static' cause an error ?
Date Sun, 23 Apr 2017 16:43:43 -0700
Organization None to speak of
Lines 40
Message-ID <lno9vmpu4w.fsf@kst-u.example.com> (permalink)
References <64abf1f2-1c45-4b1b-95cf-a88133813085@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Injection-Info mx02.eternal-september.org; posting-host="b06baaefdd2d8c25f7a310fe1662b016"; logging-data="29722"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Rrj2sQE1a9Eb359mwpY0/"
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)
Cancel-Lock sha1:VViJQ0maA61oBe7fNf+sHU3YtWQ= sha1:dnAsPD7MgBoKsT7VOepMtRry3JI=
Xref csiph.com comp.lang.c:108379

Show key headers only | View raw


fl <rxjwg98@gmail.com> writes:
> After I copy a code snippet to a test .c project, I have such an error when
> I carelessly add a 'static' key word at the beginning.
>
> "28 expression must have a constant value"
>
>
>
> static	const UART_HWAttrs uartHWAttrs[EK_UARTCOUNT] = {
> 	    {
> 	        .baseAddr = UART0_BASE,
> 	        .intNum = INT_UART0,
> 	        .intPriority = (~0),
> 	        .flowControl = UART_FLOWCONTROL_NONE,
> 	        .ringBufPtr  = uartTivaRB[0],
> 	        .ringBufSize = sizeof(uartTivaRB[0])
> 	    }
> 	};
> .............
>
>
> Can you tell me why 'static' can cause such an error?
> What rule does it violate?

The error message told you that the initializers have to be constant
expressions.  An indexing operation is not a constant expression (even
if it refers to an array object with constant initialization).

A simpler example:

    const int arr[] = { 10, 20 };
    const int x = arr[0];

The initializer for x is invalid.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Why does 'static' cause an error ? fl <rxjwg98@gmail.com> - 2017-04-23 11:17 -0700
  Re: Why does 'static' cause an error ? Noob <root@127.0.0.1> - 2017-04-23 22:00 +0200
    Re: Why does 'static' cause an error ? Richard Heathfield <rjh@cpax.org.uk> - 2017-04-23 22:22 +0100
  Re: Why does 'static' cause an error ? bartc <bc@freeuk.com> - 2017-04-23 21:34 +0100
    Re: Why does 'static' cause an error ? Keith Thompson <kst-u@mib.org> - 2017-04-23 16:45 -0700
      Re: Why does 'static' cause an error ? fl <rxjwg98@gmail.com> - 2017-04-23 17:44 -0700
        Re: Why does 'static' cause an error ? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2017-04-23 20:26 -0700
      Re: Why does 'static' cause an error ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-04-24 13:14 +0100
        Re: Why does 'static' cause an error ? Nick Bowler <nbowler@draconx.ca> - 2017-04-24 18:20 +0000
  Re: Why does 'static' cause an error ? Jerry Stuckle <jstucklex@attglobal.net> - 2017-04-23 17:52 -0400
    Re: Why does 'static' cause an error ? jacobnavia <jacob@jacob.remcomp.fr> - 2017-04-24 00:57 +0200
  Re: Why does 'static' cause an error ? Keith Thompson <kst-u@mib.org> - 2017-04-23 16:43 -0700
    Re: Why does 'static' cause an error ? David Brown <david.brown@hesbynett.no> - 2017-04-24 10:16 +0200

csiph-web