eliben: Thanks!
diff --git a/pycparser/c_generator.py b/pycparser/c_generator.py
index 0575b8b..4c86f84 100644
--- a/pycparser/c_generator.py
+++ b/pycparser/c_generator.py
@@ -283,8 +283,8 @@ class CGenerator(object):
         for name in n.name:
             if isinstance(name, c_ast.ID):
                 s += '.' + name.name
-            elif isinstance(name, c_ast.Constant):
-                s += '[' + name.value + ']'
+            else:
+                s += '[' + self.visit(name) + ']'
         s += ' = ' + self._visit_expr(n.expr)
         return s
 

Constant expressions in designated initializers are not generated back to C
While pycparser correctly parses a constant-expression in a designated initializer (the AST is correct), it fails to write it back when generating C code.

Consider the following code:
```C
void myFunction(void)
{
  int array[3] = {[0] = 0, [1] = 1, [1+1] = 2};
}
```
Parsing it, then using `CGenerator` to generate the source produces:
```C
void myFunction(void)
{
  int array[3] = {[0] = 0, [1] = 1, = 2};
}
```

The C99 grammar describes the designator part of designated initializers as:
```ebnf
designator: [ constant-expression ]
            . identifier
```
(See §6.7.8 in http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf)

The ```CGenerator.visit_NamedInitializer``` currently only considers the `ID` and `Constant` types.
The `Constant` branch should either be extended to other types or be an `else:` branch.
diff --git a/tests/test_c_generator.py b/tests/test_c_generator.py
index 9385e80..4e38f28 100644
--- a/tests/test_c_generator.py
+++ b/tests/test_c_generator.py
@@ -228,6 +228,11 @@ class TestCtoC(unittest.TestCase):
             }
             ''')
 
+    def test_issue246(self):
+        self._assert_ctoc_correct(r'''
+            int array[3] = {[0] = 0, [1] = 1, [1+1] = 2};
+            ''')
+
     def test_exprlist_with_semi(self):
         self._assert_ctoc_correct(r'''
             void x() {

pip install -e .
parse_log_pytest
pytest
pytest
3.6
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs @ file:///opt/conda/conda-bld/attrs_1642510447205/work
certifi==2021.5.30
importlib-metadata @ file:///tmp/build/80754af9/importlib-metadata_1631916693255/work
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
more-itertools @ file:///tmp/build/80754af9/more-itertools_1637733554872/work
packaging @ file:///tmp/build/80754af9/packaging_1637314298585/work
pluggy @ file:///tmp/build/80754af9/pluggy_1615976315926/work
py @ file:///opt/conda/conda-bld/py_1644396412707/work
-e git+https://github.com/eliben/pycparser.git@168f54c3ae324c3827d22fb90e456653e6fe584a#egg=pycparser
pyparsing @ file:///tmp/build/80754af9/pyparsing_1635766073266/work
pytest==6.2.4
toml @ file:///tmp/build/80754af9/toml_1616166611790/work
typing_extensions @ file:///opt/conda/conda-bld/typing_extensions_1647553014482/work
zipp @ file:///tmp/build/80754af9/zipp_1633618647012/work

name: pycparser
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - attrs=21.4.0=pyhd3eb1b0_0
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - importlib-metadata=4.8.1=py36h06a4308_0
  - importlib_metadata=4.8.1=hd3eb1b0_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - more-itertools=8.12.0=pyhd3eb1b0_0
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - packaging=21.3=pyhd3eb1b0_0
  - pip=21.2.2=py36h06a4308_0
  - pluggy=0.13.1=py36h06a4308_0
  - py=1.11.0=pyhd3eb1b0_0
  - pyparsing=3.0.4=pyhd3eb1b0_0
  - pytest=6.2.4=py36h06a4308_2
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - toml=0.10.2=pyhd3eb1b0_0
  - typing_extensions=4.1.1=pyh06a4308_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zipp=3.6.0=pyhd3eb1b0_0
  - zlib=1.2.13=h5eee18b_1
prefix: /opt/conda/envs/pycparser

tests/test_c_generator.py::TestCtoC::test_issue246
tests/test_c_generator.py::TestFunctionDeclGeneration::test_partial_funcdecl_generation tests/test_c_generator.py::TestCtoC::test_casts tests/test_c_generator.py::TestCtoC::test_comma_op_assignment tests/test_c_generator.py::TestCtoC::test_comma_op_in_ternary tests/test_c_generator.py::TestCtoC::test_comma_operator_funcarg tests/test_c_generator.py::TestCtoC::test_complex_decls tests/test_c_generator.py::TestCtoC::test_compound_literal tests/test_c_generator.py::TestCtoC::test_enum tests/test_c_generator.py::TestCtoC::test_enum_typedef tests/test_c_generator.py::TestCtoC::test_expr_list_in_initializer_list tests/test_c_generator.py::TestCtoC::test_exprlist_with_semi tests/test_c_generator.py::TestCtoC::test_exprlist_with_subexprlist tests/test_c_generator.py::TestCtoC::test_exprs tests/test_c_generator.py::TestCtoC::test_generate_struct_union_enum_exception tests/test_c_generator.py::TestCtoC::test_initlist tests/test_c_generator.py::TestCtoC::test_issue36 tests/test_c_generator.py::TestCtoC::test_issue37 tests/test_c_generator.py::TestCtoC::test_issue83 tests/test_c_generator.py::TestCtoC::test_issue84 tests/test_c_generator.py::TestCtoC::test_krstyle tests/test_c_generator.py::TestCtoC::test_nest_initializer_list tests/test_c_generator.py::TestCtoC::test_nest_named_initializer tests/test_c_generator.py::TestCtoC::test_pragma tests/test_c_generator.py::TestCtoC::test_statements tests/test_c_generator.py::TestCtoC::test_struct_decl tests/test_c_generator.py::TestCtoC::test_switchcase tests/test_c_generator.py::TestCtoC::test_ternary tests/test_c_generator.py::TestCtoC::test_trivial_decls
pycparser/c_generator.py
pycparser/c_generator.py