Click here to Skip to main content
15,557,928 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
honey the codewitch17-Sep-22 23:20
mvahoney the codewitch17-Sep-22 23:20 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
k505418-Sep-22 6:04
mvek505418-Sep-22 6:04 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
honey the codewitch18-Sep-22 6:10
mvahoney the codewitch18-Sep-22 6:10 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
k505418-Sep-22 6:51
mvek505418-Sep-22 6:51 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
honey the codewitch18-Sep-22 7:01
mvahoney the codewitch18-Sep-22 7:01 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
CPallini18-Sep-22 21:48
mveCPallini18-Sep-22 21:48 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
honey the codewitch17-Sep-22 23:23
mvahoney the codewitch17-Sep-22 23:23 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
Randor 18-Sep-22 2:23
professional Randor 18-Sep-22 2:23 
i think you should see the rule at C++11 7.16.1.4 paragraph 4

You are passing a function as an argument to a variadic function. That falls under the 'undefined behavior' description. This is why you get the default argument promotion.

As I said, just look it up and read the language spec.

honey the codewitch wrote:
The thing is, all the documentation you've pointed me to suggests it should be doing the same thing in both cases.
Well, there are two things you need to look at
  • The rules of default argument promotion.
  • The rules of passing arguments to variadic functions.
The spec clearly says that passing a function as an argument to a variadic function is undefined behavior. This is likely why you see the 'default argument promotion'.

It also mentions addressable object types and register storage.
C++
printf("%c\n",65);
This is passed in a register, this is defined behavior.

...
C++
printf("%c\n",foo<-1>::test());
This is passed as a function. C11 7.16.1.4 paragraph 4 says this is undefined behavior.

I do see a proposal for C23 in the pipeline but it hasn't been voted on yet as far as I can tell.
I was wrong, looks like N2975 passed with 17 Yes, 0 No and two abstains.

You still haven't said what language version you are using or compiler.

modified 18-Sep-22 8:33am.

GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
honey the codewitch18-Sep-22 2:28
mvahoney the codewitch18-Sep-22 2:28 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
Randor 18-Sep-22 2:56
professional Randor 18-Sep-22 2:56 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
honey the codewitch18-Sep-22 6:16
mvahoney the codewitch18-Sep-22 6:16 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
Randor 18-Sep-22 7:02
professional Randor 18-Sep-22 7:02 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
honey the codewitch18-Sep-22 7:03
mvahoney the codewitch18-Sep-22 7:03 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
honey the codewitch18-Sep-22 7:20
mvahoney the codewitch18-Sep-22 7:20 
PraiseRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
Randor 18-Sep-22 7:46
professional Randor 18-Sep-22 7:46 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
honey the codewitch18-Sep-22 7:53
mvahoney the codewitch18-Sep-22 7:53 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
Randor 18-Sep-22 7:55
professional Randor 18-Sep-22 7:55 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
honey the codewitch18-Sep-22 7:59
mvahoney the codewitch18-Sep-22 7:59 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
Randor 18-Sep-22 3:35
professional Randor 18-Sep-22 3:35 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
Daniel Pfeffer17-Sep-22 21:31
professionalDaniel Pfeffer17-Sep-22 21:31 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
honey the codewitch17-Sep-22 23:18
mvahoney the codewitch17-Sep-22 23:18 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
harold aptroot18-Sep-22 10:17
harold aptroot18-Sep-22 10:17 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
Randor 18-Sep-22 10:53
professional Randor 18-Sep-22 10:53 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
harold aptroot18-Sep-22 12:01
harold aptroot18-Sep-22 12:01 
JokeRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
Randor 18-Sep-22 12:13
professional Randor 18-Sep-22 12:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.