首页 \ 问答 \ gcc是否真的将原型视为函数并且它们的参数是否已分配内存?(Does gcc actually treat prototypes as functions and do their parameters have memory allocated?)

gcc是否真的将原型视为函数并且它们的参数是否已分配内存?(Does gcc actually treat prototypes as functions and do their parameters have memory allocated?)

我有一个关于C的设计的奇怪的具体问题,并且关于编程和语言设计。

这是它的基础:如果我调用了一个我只有原型而未分配的函数,我是否会调用实际的C函数数据结构? 换句话说,这在任何意义上都是真正的功能,或者原型是否会以某种有代表性的方式由gcc处理,可能使用不同的数据结构? 该问题中的具体问题是关于是否为使用原型声明的参数分配内存以及是否创建了空范围。

Gcc当然不会让你这样做,但是如果它会写出通常会写的相同的机器代码而且我确实尝试调用一个只有原型的函数,那么失败的是:

  1. 原型并不是所有意义上的功能

  2. 参数实际上不是声明,因此它们不代表具有正确地址和正常行为的已分配内存

  3. 由于没有大括号,gcc没有或者不能生成这个“函数”的范围被添加到堆栈中,使得参数声明荒谬,因为它们没有被声明的范围(因此它们不是 - 因此没有地址)

  4. 有一个范围创建,它的内容可能会进入堆栈,但执行死亡,因为功能块中没有指令来推进内存中的程序

  5. 你可以从技术上思考,并将原型与功能完全一样,问题是它们什么都不做!

  6. 我完全错过了别的东西

我不知道为什么这个问题对我来说很重要 - 但我想如果重要的是一切都很重要 - 这有点让我疯狂......

谢谢大家!


I have a strange specific question about the design of C and really about programming and language design in general.

This is the basis of it: If I called a function that I had only prototyped, not assigned, would I be making a call to the actual C function data structure? In other words would this be a genuine function in every sense, or would the prototype be treated by gcc in a somewhat representative way, likely using a different data structure? The specific point within that question is about whether memory is allocated for the parameters declared with the prototype and whether or not an empty scope is created.

Gcc won't let you do this of course but if it would write the same machine code it normally would and I did try to call to a function that had only been prototyped, would the failure be:

  1. prototypes aren't in all senses functions

  2. the parameters aren't actually declarations, so they don't represent allocated memory with proper addresses and normal behaviors

  3. since there were no curly brackets, gcc didn't, or couldn't, generate a scope for this "function" to be added to the stack, making the parameter declarations absurd since there is no scope for them to be declared in (thus they aren't - thus no addresses)

  4. there is a scope created, it's contents could otherwise go on the stack, but execution dies because there were no instructions in the function block to advance the program in memory

  5. you can technically think of, and treat prototypes exactly like functions, problem is they don't do anything!

  6. something else I have completely missed

I have no idea why this question matters to me - but I guess if anything matters than everything matters - and it's kinda driving me crazy...

Thanks all!


原文:https://stackoverflow.com/questions/42607980
更新时间:2023-01-04 10:01

最满意答案

您可以使用.target伪类。 为此定义下一个CSS规则:

HTML:

<div class="product">
  <img src="http://placehold.it/100x100"/>
  <a href="#shoes">Show Shoes</a>
</div>

<div class="product-highlight" id="shoes">
  <p>These are the shoes</p>
</div>

CSS:

#shoes {
    display: none; /* hide by default */
}
#shoes:target, /* and show either if class show is present (on click) */
#shoes.show {  /* or location hash matches id "shoes" */
    display: block;
}

在JS中你会添加类show:

$(document).ready(function() {

  $('.product-highlight').hide();

  $('a[href$=shoes').click(function() {
    $('#shoes').addClass('show');
  });

});

从索引页面重定向时,您还需要设置哈希#shoes:

$(document).ready(function() {

  $('a[href$=shoes]').click(function() {

    window.location.href= 'http://sample.com/products.php/#shoes';

  });
});

请参阅此页面

要么

$(document).ready(function(){
    $(".Test2").hide();
    $(".Test1").show();

    $('.Test1').click(function(){
        $(".Test2").slideToggle();
    });
});

工作时尚


You can make use of.target pseudo-class. For this define next CSS rules:

HTML:

<div class="product">
  <img src="http://placehold.it/100x100"/>
  <a href="#shoes">Show Shoes</a>
</div>

<div class="product-highlight" id="shoes">
  <p>These are the shoes</p>
</div>

CSS:

#shoes {
    display: none; /* hide by default */
}
#shoes:target, /* and show either if class show is present (on click) */
#shoes.show {  /* or location hash matches id "shoes" */
    display: block;
}

and in JS you would add class show:

$(document).ready(function() {

  $('.product-highlight').hide();

  $('a[href$=shoes').click(function() {
    $('#shoes').addClass('show');
  });

});

When redirecting from index page you would also need to set a hash #shoes:

$(document).ready(function() {

  $('a[href$=shoes]').click(function() {

    window.location.href= 'http://sample.com/products.php/#shoes';

  });
});

Refer This page

or

$(document).ready(function(){
    $(".Test2").hide();
    $(".Test1").show();

    $('.Test1').click(function(){
        $(".Test2").slideToggle();
    });
});

WORKING FIDDLE

相关问答

更多
  • $(".header").click(function() { $('.content').slideToggle().toggleClass('active'); if ($('.content').hasClass('active')) { $('.header span').text('Collapse'); } else { $('.header span').text('Expand'); } }); $('button').click(functi ...
  • 尝试在点击时删除卡上的“翻转”课程。 function clickListener(card) { card.addEventListener( "click", function() { $('.card.effect__click').removeClass('flipped'); var c = this.classList; c.contains("flipped") === ...
  • 这不起作用,因为使用parent类时存在Bootstrap错误/问题。 它依赖于使用围绕collapse元素包裹的panel类。 https://github.com/twbs/bootstrap/issues/10966 更新了JSFiddle
  • $(this).get(0).scrollIntoView(); 将此行添加到.click函数中。 小提琴 $(this).get(0).scrollIntoView(); Add this line into the .click function. Fiddle
  • 干得好: http://jsfiddle.net/tvyfxey6/6/ $('#play').on('click', function(evt) { alert('click'); $('#play').hide(); $('#img').hide(); $('#video').html('