Re: Digest Number 373

William Rance <[email protected]> Sat, 07 Jan 2006 13:47:09 +0800
Newsgroups gmane.comp.programming.cppug
Message-ID <[email protected]>
This also worked uner Visual C++ 6 - console application, no changes to IDE

#include<stdio.h>

int before()
{
      printf("HELLO\n");
      return 1;
}

const int i = before();

int main()
{
   printf("main\n");
   return 0;
}

The real question is what your interviewer is really asking - for this you 
should also provide the questions immediately preceding this one.

At 04:31 PM 12/31/2005, you wrote:
>
>There are 3 messages in this issue.
>
>Topics in this digest:
>
>       1. Re: Re: [c-prog] How to execute the user defined ...
>            From: Shiju Krishnan <[email protected]>
>       2. Re: please look into this and respond
>            From: "rafael_ortolan_666" <[email protected]>
>       3. Re: Re: [c-prog] How to execute the user defined ...
>            From: sumit kumar <[email protected]>
>
>
>________________________________________________________________________
>________________________________________________________________________
>
>Message: 1
>    Date: Fri, 30 Dec 2005 09:14:01 +0530
>    From: Shiju Krishnan <[email protected]>
>Subject: Re: Re: [c-prog] How to execute the user defined ...
>
>#include<stdio.h>
>int before()
>{
>     printf("HELLO\n");
>     return 1;
>}
>int i = before();
>
>int main()
>{
>     printf("main\n");
>     return 0;
>}
>
>this work out on solaris
>
>Regards
>Shiju K.
>
>On 12/28/05, sumit kumar <[email protected]> wrote:
> >
> >  At 05:54 2005-12-27, Jitendra Kumar wrote:
> > >Hi all to the members of wonderful forum,
> > >
> > >Y'day i had an interview, this was the qstn:
> > >
> > >Write a program which will execute before the main
> > >function, dont use #pragma or compiler level programs?
> >
> > what language?  If C++, trivial:   write a struct
> > or class with your program in the constructor.
> > define an instance as a global variable.
> >
> > in C?  I have no idea.
> >
> >
> > >Pls post the answer.
> > >Thanku,
> > >
> > >Jitendra
> >
> >
> > *Maneesh Anand Samria <[email protected]>* wrote:
> >
> > Lets try this
> > #include<stdio.h>
> > int before()
> > {
> >  printf("HELLO");
> >  return 1;
> > }
> > int i = before();
> > void main()
> > {
> >  printf("main");
> > }
> >  This wont work since initialiser must be a constant.
> >
> > Regards,
> > Sumit kumar
> >
> > ------------------------------
> > Yahoo! for Good - Make a difference this 
> year.<http://us.rd.yahoo.com/mail_us/taglines/charity/*http://brand.yahoo.com/cybergivingweek2005/>
> >  ------------------------------
> > YAHOO! GROUPS LINKS
> >
> >
> >    -  Visit your group "cppug <http://groups.yahoo.com/group/cppug>" on
> >    the web.
> >
> >    -  To unsubscribe from this group, send an email to:
> > 
> [email protected]<[email protected]?subject=Unsubscribe>
> >
> >    -  Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> >    Service <http://docs.yahoo.com/info/terms/>.
> >
> >
> >  ------------------------------
> >
> >
>
>
>[This message contained attachments]
>
>
>
>________________________________________________________________________
>________________________________________________________________________
>
>Message: 2
>    Date: Fri, 30 Dec 2005 16:00:05 -0000
>    From: "rafael_ortolan_666" <[email protected]>
>Subject: Re: please look into this and respond
>
>Hi,
>
>One approach to make this work in VC is to use inline assembly:
>
>void change() {
>     long a[2];
>     int k;
>     k = 0;
>l1: k = 1;
>l2: //k = (&&l2 - &&l1);
>     //calculate the lenght of the instruction to jump over
>     __asm {
>         mov eax, l2 ;
>         sub eax, l1 ;
>         mov k, eax  ;
>     }
>     //a[4] -> return address put on the stack by "call"
>     a[4] += k;
>}
>
>I have made this in VC7 and it worked fine.
>Post any doubts that you have regarding the functionality
>of this example.
>
>Regards,
>Rafael Giovanni A. Ortolan.
>
>
>--- In [email protected], sumit kumar <sumit_india1998@y...> wrote:
> >
> >   Please Refer Bottem Post....
> >
> >   > > Hi geeks,
> > > > can any body give me the code for the following
> > > > void main()
> > > > {
> > > >   int i=5;
> > > >   change();
> > > >   i=10;
> > > >   printf("%d", i);
> > > > }  // end of main
> > > > write something in change() function only, such that after
>executing the
> > > > program it should print 5 but not 10;
> > > > i know the method but i dont know how to implement it,
> > > > HINT: here we have increment the program counter.
> >
> >   > This problem demonstrates havocs that may be caused by Buffer
>Overrun.
> > > void change() {
> > >      long a[2];
> > >      int k;
> > >      k = 0;
> > >  l1: k = 1;
> > >  l2: k = (&&l2 - &&l1);
> > >      a[3] += k;
> > > }
> >
> >   > If you don't initialize  the k to zero and reinitialize it to the 1,
> > > compiler may not generate the code for the instruction of k=1; but may
> > > put the 1 at the stack address of k directly. all that is because of
> > > optimization. And you may fail to find the diff btw the labels.
> > >
> > > Check the archieves for the same problem. We had spent a lot of energy
> > > and bandwidth on this. The only point behind these problems is to
> > > learn the logic. How variables are used in stacks, and where the
> > > programs may lead to, if not properly written.
> >
> >
> >   Dear All,
> >   If this code is run on VC++ it would report an error i.e. :
> >
> >   error C2059: syntax error : '&&'
> >
> >   on unix it works fine, but I dont understand use of "&&" before
>label name I mean can we extract addresses of labels if yes why VC++
>compiler dosen't recognise this. Can any of us elaborate more on this.
>So the picture becomes more clear, If you refer to some previous post
>chain please mention dates because finding some perticular information
>from a whole lot is pretty difficult and would take days.
> >
> >   Thanks and Regards,
> >   Sumit Kumar
> >   +91-80-30956948
> >
> >
> >
> >
> > ---------------------------------
> >  Yahoo! DSL Something to write home about. Just $16.99/mo. or less
> >
>
>
>
>
>
>
>________________________________________________________________________
>________________________________________________________________________
>
>Message: 3
>    Date: Fri, 30 Dec 2005 07:57:55 -0800 (PST)
>    From: sumit kumar <[email protected]>
>Subject: Re: Re: [c-prog] How to execute the user defined ...
>
>reply inline...
>Shiju Krishnan <[email protected]> wrote:    >#include<stdio.h>
> >int before()
> >{
> >    printf("HELLO\n");
> >    return 1;
> >}
> >int i = before();
> >int main()
> >{
> >    printf("main\n");
> >    return 0;
> >}
>
> >this work out on solaris
>
>   That must be because of some bug on solaris C compiler you are using 
> since GCC an VC report error ::: error C2099: initializer is not a constant
>
>   Regards,
>   Sumit Kumar
>   +91-80-30956948
> >Regards
> >Shiju K.
>
>
>   On 12/28/05, sumit kumar <[email protected]> wrote:      At 
> 05:54 2005-12-27, Jitendra Kumar wrote:
> >Hi all to the members of wonderful forum,
> >
> >Y'day i had an interview, this was the qstn:
> >
> >Write a program which will execute before the main
> >function, dont use #pragma or compiler level programs?
>
>what language?  If C++, trivial:   write a struct
>or class with your program in the constructor.
>define an instance as a global variable.
>
>in C?  I have no idea.
>
>
> >Pls post the answer.
> >Thanku,
> >
> >Jitendra
>Maneesh Anand Samria < [email protected]> wrote:
>     Lets try this
>   #include<stdio.h>
>int before()
>{
>  printf("HELLO");
>  return 1;
>}
>int i = before();
>void main()
>{
>  printf("main");
>}
>
>     This wont work since initialiser must be a constant.
>
>   Regards,
>   Sumit kumar
>
>
>
>---------------------------------
>   Yahoo! for Good - Make a difference this year.
>
>---------------------------------
>   YAHOO! GROUPS LINKS
>
>
>     Visit your group "cppug" on the web.
>
>     To unsubscribe from this group, send an email to:
>   [email protected]
>
>     Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service .
>
>
>---------------------------------
>
>
>
>
>
>
>---------------------------------
>   YAHOO! GROUPS LINKS
>
>
>     Visit your group "cppug" on the web.
>
>     To unsubscribe from this group, send an email to:
>  [email protected]
>
>     Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
>
>
>---------------------------------
>
>
>
>
>
>
>---------------------------------
>Yahoo! Shopping
>  Find Great Deals on Holiday Gifts at Yahoo! Shopping
>
>[This message contained attachments]
>
>
>
>________________________________________________________________________
>________________________________________________________________________
>
>
>
>------------------------------------------------------------------------
>Yahoo! Groups Links
>
>
>
>
>------------------------------------------------------------------------



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/cppug/

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/