From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: dalanicolai Newsgroups: gmane.emacs.devel Subject: Re: What is the recommended way to find out the number of arguments passed to a module function? Date: Wed, 10 Jan 2024 21:41:56 +0100 Message-ID: References: <83jzohm23r.fsf@gnu.org> <83il41lzkj.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000e58f6c060e9d7641" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28304"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Jan 10 21:43:24 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rNfQ2-0007BB-UV for ged-emacs-devel@m.gmane-mx.org; Wed, 10 Jan 2024 21:43:22 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rNfOy-0006DF-Sq; Wed, 10 Jan 2024 15:42:16 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rNfOx-0006Co-4u for emacs-devel@gnu.org; Wed, 10 Jan 2024 15:42:15 -0500 Original-Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rNfOt-0008UW-1D; Wed, 10 Jan 2024 15:42:14 -0500 Original-Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-3368b9bbeb4so4459823f8f.2; Wed, 10 Jan 2024 12:42:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704919328; x=1705524128; darn=gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=+YeSQkyqAcMEMAGEf97gSLHPrdHUdCtRGlNAhLc9X84=; b=VIZLVAdhJx9/5qtA6TBc9NnxYvQ6KAXDD435xZ0tUfJ86l9zIcL4JZnZLJolHA4eB8 QKTAGSykNkju1CgcycEV08xyQCWqJ5yzkM7Kiag4PTrvE+/X8qjxyh4YZ9ZaimUOC/sU tk0JNZM35U9AGJI9XWWs6sjX03B5hJsIyKZZdZhgpoUqsMULXK9sbChHBjbq38RwEiZf C4bEjmmMNMfbEHeQjV5Ua3lB6w7Scj4GGQXYK8DvwdFvr8Cc0SxzzKq/qB6ta9IgH7HN FV9eHZY0b1hfwQ+HrgLynfgkV/walw0xH8oXpOmiJfYXEjfnyuiQcluYu6SaihWsabBn Iehw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704919328; x=1705524128; 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=+YeSQkyqAcMEMAGEf97gSLHPrdHUdCtRGlNAhLc9X84=; b=dwhMzJk2ZE6AwUItX5s5m8QDB5Bqec1GbOaz932walqscPdTodyxZ2gvahXKbMAntO RCw/Tznr1Z97R+kfwKaTYfMAeTvo9IIEIuVvc+xKdTfOKBsuFcN0sXqZ65mub3JOvAPF /yTLF+BE6d9wXgWtRAIOqFzIaI8UqxAopOiGImy4QqDMBqmPbllbn7f9XFnhA8cgwiJT u2HpZO5Gq1R8cIBx9L6KHNLRMSpWtJ8wFIEK+4ROvXiyUuUWbz3VXBqm5mDUcWgrA80V 5Vw49uvzUHXNYgUKBolw9SWJK4gZiCA6hm8PGfH++lBvQ7q/OuDqQj9ltLnGkhXCcV++ e9Xg== X-Gm-Message-State: AOJu0Yw4d1HYF6TdWWjongGkcUej40vAtrWs+y/M7vcshighCDl5kggL NZShVl/NSzcN+4rNUgO+XXLg4n9dGqE/NG5hqIth/3+v X-Google-Smtp-Source: AGHT+IEWvP+SEkukk6qEiT8dr4i15rVTcIHXJjiGOal6RO4Ux93xTcg/WkB9FVHAy3nwvCsm6gIpMwFi/aeb8MgwTgQ= X-Received: by 2002:a05:600c:3c92:b0:40d:5b0c:768b with SMTP id bg18-20020a05600c3c9200b0040d5b0c768bmr3605wmb.206.1704919327672; Wed, 10 Jan 2024 12:42:07 -0800 (PST) In-Reply-To: <83il41lzkj.fsf@gnu.org> Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=dalanicolai@gmail.com; helo=mail-wr1-x42c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:314824 Archived-At: --000000000000e58f6c060e9d7641 Content-Type: text/plain; charset="UTF-8" Thanks Eli. Also, I realize now, that sizeof works differently on an array and a pointer (to an array) (AFAIU). I guess I will slowly or quickly get used to these (initial) pitfalls. On Wed, 10 Jan 2024 at 21:10, Eli Zaretskii wrote: > > From: dalanicolai > > Date: Wed, 10 Jan 2024 21:05:22 +0100 > > > > Ah okay, well I am completely new to C, so I am still finding out things > (e.g. I have not 'actively' used > > ptrdiff yet). > > But indeed the 'nargs' just give the number of passed args (obviously). > > > > I had checked the 'sizeof' the args array when passing an argument and > without passing an > > argument, > > and it was the same. Then the docs mention that NARGS is the 'required' > number of arguments, > > I had misunderstood it a little (of course the required number is > variable, but somehow I assumed it > > would be 1 in this case). So sometimes I overlook the 'obvious', and > because I had spent some time > > on testing > > things already, I decided to just ask here. > > The args[] array gets allocated exactly to accommodate nargs > arguments, so you should never access args[] beyond the index nargs-1. > > > Anyway, as usual, thanks for your quick and helpful answer! > > You're welcome. > --000000000000e58f6c060e9d7641 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks Eli.

Also, I realize = now, that sizeof works differently on an array and a pointer (to an array) = (AFAIU).
I guess I will slowly or quickly get used to these (init= ial) pitfalls.


On Wed, 10 Jan 2024 at 21:10, Eli Za= retskii <eliz@gnu.org> wrote:
=
> From: dalanico= lai <dalanico= lai@gmail.com>
> Date: Wed, 10 Jan 2024 21:05:22 +0100
>
> Ah okay, well I am completely new to C, so I am still finding out thin= gs (e.g. I have not 'actively' used
> ptrdiff yet).
> But indeed the 'nargs' just give the number of passed args (ob= viously).
>
> I had checked the 'sizeof' the args array when passing an argu= ment and without passing an
> argument,
> and it was the same. Then the docs mention that NARGS is the 'requ= ired' number of arguments,
> I had misunderstood it a little (of course the required number is vari= able, but somehow I assumed it
> would be 1 in this case). So sometimes I overlook the 'obvious'= ;, and because I had spent some time
> on testing
> things already, I decided to just ask here.

The args[] array gets allocated exactly to accommodate nargs
arguments, so you should never access args[] beyond the index nargs-1.

> Anyway, as usual, thanks for your quick and helpful answer!

You're welcome.
--000000000000e58f6c060e9d7641--