gcc是否真的将原型视为函数并且它们的参数是否已分配内存?(Does gcc actually treat prototypes as functions and do their parameters have memory allocated?)
我有一个关于C的设计的奇怪的具体问题,并且关于编程和语言设计。
这是它的基础:如果我调用了一个我只有原型而未分配的函数,我是否会调用实际的C函数数据结构? 换句话说,这在任何意义上都是真正的功能,或者原型是否会以某种有代表性的方式由gcc处理,可能使用不同的数据结构? 该问题中的具体问题是关于是否为使用原型声明的参数分配内存以及是否创建了空范围。
Gcc当然不会让你这样做,但是如果它会写出通常会写的相同的机器代码而且我确实尝试调用一个只有原型的函数,那么失败的是:
原型并不是所有意义上的功能
参数实际上不是声明,因此它们不代表具有正确地址和正常行为的已分配内存
由于没有大括号,gcc没有或者不能生成这个“函数”的范围被添加到堆栈中,使得参数声明荒谬,因为它们没有被声明的范围(因此它们不是 - 因此没有地址)
有一个范围创建,它的内容可能会进入堆栈,但执行死亡,因为功能块中没有指令来推进内存中的程序
你可以从技术上思考,并将原型与功能完全一样,问题是它们什么都不做!
我完全错过了别的东西
我不知道为什么这个问题对我来说很重要 - 但我想如果重要的是一切都很重要 - 这有点让我疯狂......
谢谢大家!
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:
prototypes aren't in all senses functions
the parameters aren't actually declarations, so they don't represent allocated memory with proper addresses and normal behaviors
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)
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
you can technically think of, and treat prototypes exactly like functions, problem is they don't do anything!
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
最满意答案
您可以使用.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'; }); });
or
$(document).ready(function(){ $(".Test2").hide(); $(".Test1").show(); $('.Test1').click(function(){ $(".Test2").slideToggle(); }); });
相关问答
更多-
$(".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
单击div时滚动到div(Scroll to div on clicking the div)[2022-03-12]
$(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('你已经使用jQuery提供的animate方法,我希望建议你更简单和更好的解决方案。 $('.box').click(function() { $(this).toggleClass('opened'); $('.box').not(this).removeClass('opened'); }); .box { height: 3rem; width: 10rem; background-color: #be6666; overflow: hidden; tran ...当您单击触发器时,这个小的jQuery脚本将显示相关的div并隐藏其他div(可能存在css问题,我为此测试删除了它): $(document).ready(function() { $('.sqtrigger').on('click', function(e) { var targetId = this.id.replace('x', ''); $('#info .textbox').hide(); $('#' + targetId).sh ...你的HTML代码很好,需要更改js, $(document).ready(function(){ $('#login-trigger').click(function(event){ event.stopPropagation(); $("#login-content").slideToggle(); }); $("#login-content").on("click", function (event) { event.stopP ...您可以使用.target伪类。 为此定义下一个CSS规则: HTML:These are the shoes
单击同一div内部的按钮时关闭div(Closing a div when clicking on a button which is inside of the same div)[2023-09-09]
让我试着解释一下。 当用户点击按钮时,我们的事件将触发 _doc.on('click','.close_btn',function(e) { }); 在这里我们可以使用nearest() _doc.on('click','.close_btn',function(e) { jQuery(this).closest('div').hide(); }); 如果我们想使用类选择器 _doc.on('click','.close_btn',function(e) { jQuery(this).cl ...相关文章
更多- Spark - A Fault-Tolerant Abstraction for In-Memory Cluster Computing
- CLR Via C# 3rd 阅读摘要 -- Chapter 21 – Automatic Memory Management (Garbage Collection)
- 13年7月memory point
- 关于mysql数据库memory表数据重复问题
- POJ 3620 Avoid The Lakes【DFS水题练格式Avoid The Lakes Time Limit: 1000MS Memory Limit: 65536K Total Sub】
- 使用mybatis执行sql的时候为什么会出现Parameter index out of range (1 > number of parameters, which is 0)?
- Ext 3.1版本放出,可以免费下载了
- Hadoop Map/Reduce内存限制
- Android图形缓存库Picasso内存优化
- C程序访问Hadoop
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)