Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9256435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:56:27+00:00 2026-06-18T11:56:27+00:00

According to several groups posts, the following code should work: package main import fmt

  • 0

According to several groups posts, the following code should work:

package main

import "fmt"

func demo(format string, args ...interface{}) {
  var count = len(args)
  for i := 0; i < count; i++ {
    fmt.Printf("! %s\n", args[i])
  }
  fmt.Printf("%+v\n", format)
  fmt.Printf("%+v\n", args)
  fmt.Printf(format, args)
  fmt.Printf("\n")
}

func main() {
  demo("%s %d", "Hello World", 10)
  fmt.Printf("\n\n")
  demo("%d %s", 10, "Hello")
}

And yield “Hello World 10” and “10 Hello”, but it does not. Instead it yields:

! Hello World
! %!s(int=10)
%s %d
[Hello World 10]
[Hello World %!s(int=10)] %d(MISSING)


! %!s(int=10)
! Hello
%d %s
[10 Hello]
[10 %!d(string=Hello)] %s(MISSING)

Which is to say that passing []interface{} to a function that takes …interface{} as an argument does not expand the argument and instead simply passes it as the value. The first %s expands the []interface{} into a string, and no further arguments are processed.

I’m sure there must be lots of situations where this is required in logging; but I can’t find any working examples of how to do it.

This is basically the ‘vprintf’ family of functions in C.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T11:56:28+00:00Added an answer on June 18, 2026 at 11:56 am

    I don’t think the OP program should “work”. Maybe this was intended instead(?):

    package main
    
    import "fmt"
    
    func demo(format string, args ...interface{}) {
            fmt.Printf(format, args...)
    }
    
    func main() {
            demo("%s %d\n\n", "Hello World", 10)
            demo("%d %s", 10, "Hello")
    }
    

    (Also here


    Output:

    Hello World 10
    
    10 Hello
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

**EDIT: There are several options below that would work. Please vote/comment according to your
According to several posts I've found out it's now possible to perform CAdES using
i just added a launch image to an application i wrote. According to several
I need to add an header recursively to several file according to the name
I have a loop MC which will be duplicate to stage several times according
I have a listview that contain several EditTexts created dynamically according to the number
According to the C++11 standard, is the following program well-formed and portable C++? int
According to several ask and almost satysfy answers a specialy by Remy Lebeau (thank
I have a workbook in which i have several sheets according to requirement. In
According to several searches I've made, here is what I have written in order

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.