Click here to Skip to main content
15,892,298 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: Is main() a callback function? Pin
TheGreatAndPowerfulOz22-Jan-20 10:18
TheGreatAndPowerfulOz22-Jan-20 10:18 
GeneralRe: Is main() a callback function? Pin
honey the codewitch22-Jan-20 10:53
mvahoney the codewitch22-Jan-20 10:53 
GeneralRe: Is main() a callback function? Pin
TheGreatAndPowerfulOz22-Jan-20 11:12
TheGreatAndPowerfulOz22-Jan-20 11:12 
GeneralRe: Is main() a callback function? Pin
honey the codewitch22-Jan-20 11:35
mvahoney the codewitch22-Jan-20 11:35 
GeneralRe: Is main() a callback function? Pin
TheGreatAndPowerfulOz23-Jan-20 4:29
TheGreatAndPowerfulOz23-Jan-20 4:29 
GeneralRe: Is main() a callback function? Pin
raddevus22-Jan-20 5:14
mvaraddevus22-Jan-20 5:14 
GeneralRe: Is main() a callback function? Pin
Rob Philpott22-Jan-20 5:21
Rob Philpott22-Jan-20 5:21 
GeneralRe: Is main() a callback function? Pin
k505422-Jan-20 7:38
mvek505422-Jan-20 7:38 
raddevus wrote:
* Cannot have its address taken.
* Cannot be called.


Lies. You can call main, and you can take its address. This compiles and runs in VS2019:
C++
 #include <iostream>

int main(int argc, char **argv)
{
    if(argc <= 1) {
        auto main_ptr{main};
        std::cout << "pointer to main = " << main_ptr << std::endl;
        std::cout << "exiting ..." << std::endl;
        return 0;
    }
    std::cout << "argc = " << argc << std::endl;
    main(--argc, argv);
}

Interestingly, in linux you auto main_ptr{main} is 1, but for windows it looks like an address: 0008151E

Update: I should also point out that the instances where you might need to call main from within you program are vanishingly small. In general, if you think you need to, you're almost certainly wrong.
GeneralRe: Is main() a callback function? Pin
Rick York22-Jan-20 8:12
mveRick York22-Jan-20 8:12 
GeneralRe: Is main() a callback function? Pin
PIEBALDconsult22-Jan-20 10:23
mvePIEBALDconsult22-Jan-20 10:23 
GeneralRe: Is main() a callback function? Pin
Richard MacCutchan22-Jan-20 5:24
mveRichard MacCutchan22-Jan-20 5:24 
GeneralRe: Is main() a callback function? Pin
OriginalGriff22-Jan-20 5:25
mveOriginalGriff22-Jan-20 5:25 
GeneralRe: Is main() a callback function? Pin
OriginalGriff22-Jan-20 5:24
mveOriginalGriff22-Jan-20 5:24 
GeneralRe: Is main() a callback function? Pin
Rob Philpott22-Jan-20 5:31
Rob Philpott22-Jan-20 5:31 
GeneralRe: Is main() a callback function? Pin
OriginalGriff22-Jan-20 5:42
mveOriginalGriff22-Jan-20 5:42 
GeneralRe: Is main() a callback function? Pin
Rob Philpott22-Jan-20 6:12
Rob Philpott22-Jan-20 6:12 
GeneralRe: Is main() a callback function? Pin
Rick York22-Jan-20 14:20
mveRick York22-Jan-20 14:20 
GeneralRe: Is main() a callback function? Pin
DRHuff22-Jan-20 5:39
DRHuff22-Jan-20 5:39 
GeneralRe: Is main() a callback function? Pin
OriginalGriff22-Jan-20 5:43
mveOriginalGriff22-Jan-20 5:43 
GeneralRe: Is main() a callback function? Pin
DRHuff22-Jan-20 6:26
DRHuff22-Jan-20 6:26 
GeneralRe: Is main() a callback function? Pin
OriginalGriff22-Jan-20 8:06
mveOriginalGriff22-Jan-20 8:06 
GeneralRe: Is main() a callback function? Pin
DRHuff22-Jan-20 12:30
DRHuff22-Jan-20 12:30 
GeneralRe: Is main() a callback function? Pin
TheGreatAndPowerfulOz22-Jan-20 11:10
TheGreatAndPowerfulOz22-Jan-20 11:10 
GeneralRe: Is main() a callback function? Pin
PIEBALDconsult22-Jan-20 5:43
mvePIEBALDconsult22-Jan-20 5:43 
GeneralRe: Is main() a callback function? Pin
ZurdoDev22-Jan-20 5:52
professionalZurdoDev22-Jan-20 5:52 

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.