From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by sourceware.org (Postfix) with ESMTPS id 86ED83858C66 for ; Tue, 25 Apr 2023 12:17:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 86ED83858C66 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-94f6c285d22so1054007466b.2 for ; Tue, 25 Apr 2023 05:17:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682425035; x=1685017035; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=JVXW0hnmJ0Bx+ba1orMOUwHpYXsn324foKGZ9Fjirxo=; b=EpjISBFd5SBnuKr6A7OV0eJzwbxKXi097D1HjVGLPYP8KoCA5q/cf9S7M2ugxGzR54 EHE7IqlOLL7Gqap0Vc12M2gCtvK8HiLLQ311CRd5Fgk8RoHT9T/daaeTngDWVySqri3h U+usP00qumtsnXqNAgF+yN/eWtXTvtixqT553ub3qZRYuSO8n0AI5PZziW0EN/NXJJus MCy/0EPYpfXdsmbk0Q7QOrzapReTso8xiWfYJdhwo6cl2/UJO7HLwXoMlrcjRn4qhPrx au8XnIYi9SoMaKpRaFMcff4XCE4Xa+0dkBLRjO+Wx8Kzji03jRrrq2tqF21VgfnBhEOr shaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682425035; x=1685017035; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JVXW0hnmJ0Bx+ba1orMOUwHpYXsn324foKGZ9Fjirxo=; b=iDGujHfjCJ9BY5hH/HFdFinkRU9FK8zyfQYnEKM37Ot1XMuGEOatpr58G8/q2nOtHl 80lcUTCOW6CKvj4M0UgGzRwOvRGFR1/jQFyAatp5Xj8YTsZO9hTT4dyKR7pghJmD54B0 THgQEWBjRe2SMqpFs6FF0bieZlExSWaDG8JgA9+gj13yTSoAucSwAU350766ZUNrwmPB 9dBRzJEFLc6GZoaJmvE8QGBL5s5P1PIBmAKFDUqy/ZAaUtPKCV+l+RZa6eNmHyhelOhs 60PylHTncZe/R0bjkDYuhwslgGXHIYydWnHSdj9pf0D2oL028V230j1nA0e7eWhI56l6 TOig== X-Gm-Message-State: AAQBX9ek6nvsA/xnlc0leaS2dgS7a/BjQuhaWX7UNuc1UmKWxtkgSl9g C5SiirXlHS2OwnK+J8zLxhv7A5NqXJ+teojAXR7wSAiS X-Google-Smtp-Source: AKy350bXePzaM40brL+Nj6jpaixAYmdcbuoIzlHzujpzXDCry3BXb9Ux276emyZ8u1x/VvbPm90ZFy2tclxlBAepjHw= X-Received: by 2002:a17:906:7f88:b0:94f:17b7:c4b8 with SMTP id f8-20020a1709067f8800b0094f17b7c4b8mr13039105ejr.19.1682425034914; Tue, 25 Apr 2023 05:17:14 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Tue, 25 Apr 2023 13:17:04 +0100 Message-ID: Subject: Re: zero length array example does not compile To: Jonny Grant Cc: GCC Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Tue, 25 Apr 2023 at 13:13, Jonny Grant wrote: > > Hello > > https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html > > I wondered 'this_length' refers to in that example, it doesn't compile. It's not supposed to be a complete program. > > : In function 'main': > :13:34: error: 'this_length' undeclared (first use in this function) > 13 | malloc (sizeof (struct line) + this_length); > | ^~~~~~~~~~~ > > > https://godbolt.org/z/PWEcWsrKv > > I probably the size of the struct? So that would be 4 bytes for me, as it is just the int. That doesn't seem very useful. Maybe I am missing something. Yes, you are. Look at how it's used: malloc is called to allocate sizeof(struct line) + this_length bytes. Why would it be the size of the struct? It's the number of bytes that the zero-length contents array can hold.