parameter name a of fmt package

105 views
Skip to first unread message

Delta Echo

unread,
May 25, 2021, 4:14:50 AM5/25/21
to golan...@googlegroups.com
What does the parameter name `a` stands for in fmt package's functions?

like,

func Printf(format string, a ...interface{}) (n int, err error)

Is it argument?

Jan Mercl

unread,
May 25, 2021, 5:29:49 AM5/25/21
to Delta Echo, golang-nuts
On Tue, May 25, 2021 at 10:14 AM Delta Echo <deltae...@gmail.com> wrote:

> What does the parameter name `a` stands for in fmt package's functions?

> func Printf(format string, a ...interface{}) (n int, err error)
>
> Is it argument?

It's a parameter name. ...interface{} is the type of that argument,
variadic in this case indicated by the ellipsis. Argument is for
example the expression 42 in fmt.Printf("%i\n", 42).

Within the body of Printf the 'a' parameter is typed as []interface{}.

These questions are best answered by checking the language
specification: https://golang.org/ref/spec#Function_types and
https://golang.org/ref/spec#Passing_arguments_to_..._parameters

Delta Echo

unread,
May 25, 2021, 6:14:24 AM5/25/21
to Jan Mercl, golang-nuts
> It's a parameter name. ...interface{} is the type of that argument,
variadic in this case indicated by the ellipsis.

You misunderstood my question.

My question was what does `a` refers to?

Like,
fd - file descriptor
ptr - pointer

peterGo

unread,
May 25, 2021, 8:36:04 AM5/25/21
to golang-nuts
The Go fmt Print functions use the C printf model for formatted output. The usual terminology is argument.

---

The C Programming Language
https://en.wikipedia.org/wiki/The_C_Programming_Language

B.1.2 Formatted Output

The printf functions provide formatted output conversion.

int fprintf(FILE *stream, const char *format, ...)

fprintf converts and writes output to stream under the control of format . The return value
is the number of characters written, or negative if an error occurred.

The format string contains two types of objects: ordinary characters, which are copied to the
output stream, and conversion specifications, each of which causes conversion and printing of
the next successive argument to fprintf.

---

POSIX
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html

NAME

printf - write formatted output

SYNOPSIS

printf format [argument...]

DESCRIPTION

The printf utility shall write formatted operands to the standard output. The argument operands shall be formatted under control of the format operand.

---

Linux
https://linux.die.net/man/1/printf

printf(1) — Linux manual page
 
NAME

printf - format and print data

SYNOPSIS

printf FORMAT [ARGUMENT]...

DESCRIPTION

Print ARGUMENT(s) according to FORMAT.

---

Peter

tapi...@gmail.com

unread,
May 25, 2021, 9:06:27 AM5/25/21
to golang-nuts
I think it means "any" , any values.

Gyaneshwar Rao Nampally

unread,
May 25, 2021, 12:00:21 PM5/25/21
to golang-nuts
 interface{} can take any kind of value,,,
as u specified above, it can take file descriptor and pointer.

for more , i think this will help. https://golang.org/doc/effective_go#interfaces

Reply all
Reply to author
Forward
0 new messages