Re: [C--] Segmentation fault (cannot take the address of a formal parameter)

Ning Wang <[email protected]> Fri, 27 Mar 2009 17:16:36 -0700
Newsgroups gmane.comp.lang.c--
Message-ID <[email protected]>
[email protected] wrote:
> On Fri, Mar 27, 2009 at 05:31:38AM -0700, Ning Wang wrote:
>   
>> John Dias wrote:
>>     
>>>> This is bad. Anyway, the c-- code seems correct, but the executable code
>>>>         
>>> The call to strcmp passes the wrong value for the first argument:
>>>
>>>          _fooret = foreign "C" strcmp (bits32[a_T_155], 
>>> str__a_da_289565476_1);
>>>
>>> The first argument here is not the address of the string: it is the 
>>> result of loading 32 bits from the address of the string. You want:
>>>
>>>          _fooret = foreign "C" strcmp (a_T_155, str__a_da_289565476_1);
>>>
>>> Cheers,
>>> -j
>>>       
>> The formal parameters of a C-- procedure are always passed in 
>> registers.  
>>     
>
> Always?  Is there a limit on the mumber of parameters?
>   
AFAIK, no. Because these registers are actually virtual registers.
>   
>> This suggests that there is no corresponding C-- 
>> representation for the following C code:
>>
>> int foo (int argc)
>> {
>>     int * ptr = & argc;
>>     printf ("%p\n", ptr);
>> }
>>
>> I believe it's a known issue to C-- folks, since the manual mentions no 
>> support for "varargs".  But it's still a little surprise.
>>     
>
> Which brings up an interesting question -- how does the C front end 
> translate varargs into C--?
>   
It cannot.  If a C program does not define vararg functions, then it can 
still be translated to C--.  Since qc-- honors C calling convention, so 
the translated C program can still call vararg functions defined in 
other objects files, which should be compiled by other C compilers.

Ning

_______________________________________________
Cminusminus mailing list
[email protected]
https://www.eecs.harvard.edu/mailman/listinfo/cminusminus