小编Mor*_*lde的帖子

本汇编代码中的"2 + 2"在哪里(由C中的gcc翻译)

我写了这个简单的C代码

int main()
{
    int calc = 2+2;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我希望看到它在汇编中看起来如何,所以我使用它编译它 gcc

$ gcc -S -o asm.s test.c
Run Code Online (Sandbox Code Playgroud)

结果是大约65行(Mac OS X 10.8.3),我发现这些是相关的:

在此输入图像描述

2+2在这个代码中在哪里寻找我的?

编辑:

One part of the question hasn't been addressed.

If %rbp, %rsp, %eax are variables, what values do they attain in this case?

c assembly gcc

4
推荐指数
2
解决办法
349
查看次数

C malloc仅为int*分配了8个字节

我正在尝试创建一个指向函数中6元素的指针int,以便稍后返回它,所以为了这个目的我正在使用malloc,但它似乎并没有像我预期的那样行事.这是代码:

int j = 0;
for (;j < 5; j++) {
    int * intBig = malloc(j * sizeof(int));
    printf("sizeof intBig - %ld\n", sizeof(intBig));
}
Run Code Online (Sandbox Code Playgroud)

打印与每次迭代时相同的数字8字节sizeof(intBig).而我期待一系列的4, 8, 12, 16.在这个例子中我错过了什么?

c malloc

4
推荐指数
2
解决办法
2344
查看次数

如何解释终端中可执行文件名称前的'./'前缀?

每次我编译一个C程序,比如使用cc编译器,我在当前目录中得到一个可执行文件.现在,如果我想运行它,而不是只键入a.outname_of_executable,我必须用这个组合作为前缀./a.out.

我理解背后的含义.(链接到当前目录)和..(链接到其父目录),也是/目录名之间的分隔符.

但是这是什么意思./?它只是一种正式的方式来区分引用某个东西的名称,以及运行该东西的意图(因为你/的文件名中没有)?

c unix terminal

4
推荐指数
1
解决办法
379
查看次数

顶部的"UITableView"额外空间

我不记得在UITableView为场景添加s 时看到这个额外的空间.当我从Interface Builder中的对象库中拖动默认对象时,就会发生这种情况.

为了突出差距,我将表格的背景颜色更改为灰色.

在此输入图像描述

我用以下代码填充表中的数据.

extension UserListViewController: UITableViewDataSource {
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return users.count
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = UITableViewCell(style: .Subtitle, reuseIdentifier: nil)
        cell.textLabel?.text = users[indexPath.row].name
        return cell
    }
}
Run Code Online (Sandbox Code Playgroud)

dataSourceviewDidLoad在视图控制器的内部设置了轮廓.

tableView.dataSource = self
Run Code Online (Sandbox Code Playgroud)

那么这个差距来自哪里呢?我怎么摆脱它呢?

uitableview ios swift

3
推荐指数
2
解决办法
4219
查看次数

NSLayoutConstraint 将视图固定到超级视图的底部边缘

一个可重现的例子

class ViewController: UIViewController {

   var created = false

   override func viewDidLayoutSubviews() {
      super.viewDidLayoutSubviews()
      if !created {

         let scrollView = UIScrollView()
         scrollView.backgroundColor = UIColor.grayColor()
         view.addSubview(scrollView)

         let kidView = UIView()
         kidView.backgroundColor = UIColor.redColor()
         kidView.translatesAutoresizingMaskIntoConstraints = false

         scrollView.addSubview(kidView)

         scrollView.translatesAutoresizingMaskIntoConstraints = false
         kidView.translatesAutoresizingMaskIntoConstraints = false

         view.addConstraints(
            NSLayoutConstraint.constraintsWithVisualFormat("H:|[scrollView]|", options: .AlignAllLeft, metrics: nil, views: ["scrollView": scrollView])
         )
         view.addConstraints(
            NSLayoutConstraint.constraintsWithVisualFormat("V:|[scrollView]|", options: .AlignAllLeft, metrics: nil, views: ["scrollView": scrollView])
         )

         kidView.addConstraints([
            NSLayoutConstraint(item: kidView, attribute: .Width, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1, constant: 100),
            NSLayoutConstraint(item: kidView, attribute: …
Run Code Online (Sandbox Code Playgroud)

cocoa-touch ios autolayout swift

3
推荐指数
1
解决办法
8628
查看次数

matplotlib无法正确显示3D平面的交集

我想绘制两个平面并找到它们的交叉线,但是我得到了这个结果,因为一个平面覆盖了另一个平面,所以无法分辨它们相交的位置.

3D投影应隐藏平面的不可见部分,如何使用matplotlib获得此结果?

飞机

你可以清楚地看到这些平原应该相交.

平面相交

这是我用来获得这个结果的代码

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

values = range(-10, 11)

def plotPlane(plot, normal, d, values, colorName):
    # x, y, z
    x, y = np.meshgrid(values, values)
    z = (-normal[0] * x - normal[1] * y - d) * 1. / normal[2]

    # draw plot
    plot.plot_surface(x, y, z, color=colorName)

image = plt.figure().gca(projection='3d')

plotPlane(image, [3, 2, -4], 1, values, "red")
plotPlane(image, [5, -1, 2], 4, values, "gray")

plt.show()
Run Code Online (Sandbox Code Playgroud)

python 3d matplotlib

2
推荐指数
2
解决办法
3305
查看次数

如何连接到我的LaunchPad TM4C123G

我花了一些时间尝试TM4C123G使用我的macbook上的mspdebug工具链连接到我的LaunchPad (10.10),但没有运气.

在尝试跑步的时候,$ mspdebug rf2500我得到了

usbutil: unable to find a device matching 0451:f432
Run Code Online (Sandbox Code Playgroud)

我做了一些谷歌搜索,在我看来,mspdebug工具包可能不适合我的LaunchPad版本.这可能吗?

检查后$ system_profiler SPUSBDataType我得到以下内容:

      Product ID: 0x00fd
      Vendor ID: 0x1cbe  (Texas Instruments - Stellaris)
      Version: 1.00
      Serial Number: 0E205EE1
      Speed: Up to 12 Mb/sec
      Manufacturer: Texas Instruments
      Location ID: 0x14100000 / 14
      Current Available (mA): 500
      Current Required (mA): 250
Run Code Online (Sandbox Code Playgroud)

这向我表明至少操作系统能够识别设备,对吧?如果是这样,我可以用什么其他工具链连接到设备.

embedded microcontroller texas-instruments

2
推荐指数
1
解决办法
1886
查看次数

如何在单独的文件中使用 &gt;=2 个块来渲染模板()?

由于使用Jinja2块将模板分解为单独的文件,{% block _name_ %}{% endblock %}我想在 上实现它应该相当容易Flask,但我无法理解它。

誓言

我有这个结构:

daddy_template.html
    son.html
    daughter.html
Run Code Online (Sandbox Code Playgroud)

所有模板大致有以下内容:

<!-- daddy_template.html -->
<div id="son">{% block son %}{% endblock %}</div>
<div id="daughter">{% block daughter %}{% endblock %}</div>

<!-- son.html -->
{% extends "daddy_template.html" %}
{% block son %}
<p>Knock, knock</p>
{% endblock %}

<!-- daughter.html -->
{% extends "daddy_template.html" %}
{% block daughter %}
<p>Who is it?</p>
{% endblock %}
Run Code Online (Sandbox Code Playgroud)

轮到

我只知道render_template()在 Flask 中准备一个模板并且一次只需要一个模板,所以这省略了除了函数参数中提供的一个块之外的所有内容。

from flask import Flask, render_template …
Run Code Online (Sandbox Code Playgroud)

python jinja2 flask

1
推荐指数
1
解决办法
1396
查看次数

window.onload = stuff和window.onload = stuff()之间有区别吗?

我最熟悉Python,有点用C,当我在JS中看到这种语法时,我真的很困惑

function begin () {
    console.log("done did it");
}

window.onload = begin(); // the same output as
window.onload = begin;   // this one
Run Code Online (Sandbox Code Playgroud)

在Python中,一个是传递函数的返回值,另一个是函数的指针.JS中这两个语句的语义是什么?

javascript

1
推荐指数
1
解决办法
102
查看次数

如何正确创建单例对象并在C++中使用它?

背景

我对OOP的大部分经验来自于Objective-C.在那种语言中,实例方法之间有明显的区别.因此,使用单例非常容易,没有任何副作用.

C++我没有那么幸运,我似乎无法避免由我的控制创建对象.

我有以下对象

class Window
{
private:
    Window();
    Window(Window const &windowCopy);
    void operator=(Window const &windowRight);

public:
    ~Window();
    static Window getSingleton();
};
Run Code Online (Sandbox Code Playgroud)

这是.h.大部分实现只是我cout用来在.h调用每个方法时打印消息.除了getSingleton()方法.

Window Window::getSingleton()
{
    static Window singleton;
    return singleton;
}
Run Code Online (Sandbox Code Playgroud)

这是我的主要内容

int main(int argc, char *argv[])
{
    Window::getSingleton();
    Window::getSingleton();

    std::cout << "Stack is being removed" << std::endl;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

结果

运行后,我得到以下输出

Window created   -> 0x10c9bf0e0 // This is the static …
Run Code Online (Sandbox Code Playgroud)

c++ singleton

1
推荐指数
1
解决办法
50
查看次数