Click here to Skip to main content
15,884,099 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 22:20
mvahoney the codewitch17-Sep-22 22:20 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
k505418-Sep-22 5:04
mvek505418-Sep-22 5: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 5:10
mvahoney the codewitch18-Sep-22 5:10 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
k505418-Sep-22 5:51
mvek505418-Sep-22 5: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 6:01
mvahoney the codewitch18-Sep-22 6:01 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
CPallini18-Sep-22 20:48
mveCPallini18-Sep-22 20: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 22:23
mvahoney the codewitch17-Sep-22 22:23 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
Randor 18-Sep-22 1:23
professional Randor 18-Sep-22 1: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 1:28
mvahoney the codewitch18-Sep-22 1:28 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
Randor 18-Sep-22 1:56
professional Randor 18-Sep-22 1: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 5:16
mvahoney the codewitch18-Sep-22 5:16 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
Randor 18-Sep-22 6:02
professional Randor 18-Sep-22 6: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 6:03
mvahoney the codewitch18-Sep-22 6: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 6:20
mvahoney the codewitch18-Sep-22 6:20 
PraiseRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
Randor 18-Sep-22 6:46
professional Randor 18-Sep-22 6: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 6:53
mvahoney the codewitch18-Sep-22 6:53 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
Randor 18-Sep-22 6:55
professional Randor 18-Sep-22 6: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 6:59
mvahoney the codewitch18-Sep-22 6:59 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
Randor 18-Sep-22 2:35
professional Randor 18-Sep-22 2:35 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
Daniel Pfeffer17-Sep-22 20:31
professionalDaniel Pfeffer17-Sep-22 20: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 22:18
mvahoney the codewitch17-Sep-22 22:18 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
harold aptroot18-Sep-22 9:17
harold aptroot18-Sep-22 9:17 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
Randor 18-Sep-22 9:53
professional Randor 18-Sep-22 9:53 
GeneralRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
harold aptroot18-Sep-22 11:01
harold aptroot18-Sep-22 11:01 
JokeRe: I thought I new C++ *sob* It has been inserting extra code on me this whole time. Pin
Randor 18-Sep-22 11:13
professional Randor 18-Sep-22 11: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.