Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

(OT) How can I do unless(caller) { main; } in C using GCC in Windows?

by mcandre (Initiate)
on Sep 12, 2012 at 20:41 UTC ( #993307=perlquestion: print w/ replies, xml ) Need Help??
mcandre has asked for the wisdom of the Perl Monks concerning the following question:

With help from Stack Overflow, I'm able to reproduce the Perl's scriptedmain behavior unless(caller) { main; } in C (http://rosettacode.org/wiki/Scripted_Main#C).

Trouble is, this only works with GCC/Unix, not GCC/Windows.

Full analysis and error traces: http://stackoverflow.com/questions/12395130/trouble-using-scriptedmain-in-mingw/12395171#12395171

Does anyone know how to reproduce this (https://github.com/mcandre/scriptedmain/tree/master/perl) in C so that it compiles in Windows?

Comment on (OT) How can I do unless(caller) { main; } in C using GCC in Windows?
Download Code
Re: (OT) How can I do unless(caller) { main; } in C using GCC in Windows?
by tobyink (Abbot) on Sep 12, 2012 at 20:48 UTC

    What makes you think that PerlMonks is a good place to ask for C advice?

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

      That's a fair question.

      Perlmonks is most likely to understand what unless(caller) { main; } does; that's been the largest barrier to communication so far. I basically want to replicate this snippet in as many programming languages as possible, because I prefer my software to work well in shell script environments.

      Strawberry Perl's GCC compiler happens to be the locus of the problem, because it does not recognize the same macros that GCC does in an ordinary Unix environment. Any Perl monks familiar with Strawberry Perl's internals could help with this issue.

        So you're talking about Weak symbol?

        win32 has "entry points", default is main, then WinMain, but if gcc weak symbol thing is hiding it as entry point, they you have to specify via some gcc switches what the entry point is

        what gcc is probably doing is renaming the symbol to something not main ( or _main )

        Find out what it is, then use  gcc ... -e _the_new_main

        To find out , compile the .c file to .o, I don't remember what switch to use, -O/-c, something like that. Then use objdump -x ...o to see the symbols

        Strawberry Perl's GCC compiler happens to be the locus of the problem, because it does not recognize the same macros that GCC does in an ordinary Unix environment. Any Perl monks familiar with Strawberry Perl's internals could help with this issue.

        There are no strawberry perl internals, they're the same as regular perl

        What makes you think that PerlMonks is a good place to ask for C advice?

        Why is that so strange?

        That LLVM stuff was about perl, this question isn't about perl (or embedding perl , calling perl from c ...)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://993307]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2014-07-30 11:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (230 votes), past polls