ICode9

精准搜索请尝试: 精确搜索
  • c – 将对象的实例作为函数参数传递 – 此代码是否调用未定义的行为?2019-09-01 20:18:52

    这是我在生产中运行的代码的缩小版本.我发现,我的真实代码在gcc和英特尔编译器下表现不同,我最好的猜测是未定义的行为.请考虑以下示例代码: #include <iostream> struct baseFunctor{ virtual double operator()(double x) const = 0; }; class mathObj{ const baseFunc

  • c – 将对象的第一个字段转换为对象的类型实际上是否安全?2019-09-01 14:08:38

    乍一看,这看起来像未定义的行为…… #include <iostream> struct SomeBaseClass { // ... }; struct MyFakerClass { SomeBaseClass base; void foo() { std::cout << "hello" << std::endl; } }; int main() { MyFakerClass c; MyFakerC

  • c – 修改const对象的非const成员2019-08-31 18:05:06

    我知道修改声明为常量的对象是一个UB.标题中提到的更复杂的例子怎么样? class Foo { public: Foo ( void ) { } int data; }; int main ( void ) { const Foo foo; const_cast<Foo&>(foo).data = 0; // UB? return 0; } 数据被声明为非const,

  • javascript – AngularJS文本框返回未定义的值2019-08-30 12:44:51

    当我按下我的按钮检查bootstrap模式时,我想在我的控制台中打印我的文本框的值.但我的文本框返回一个未定义的.似乎所有的代码都是完美的. 这是链接Plunker <!doctype html> <html ng-app="app" ng-controller="ModalDemoCtrl"> <head> <link href="//netdna.bootstrapcdn.com/

  • c – 初始化数组,放置新的,读取变量,定义的行为?2019-08-30 08:05:21

    给定一个类的唯一成员是char [10],它没有继承,也没有虚拟成员,它有一个构造函数,它没有以任何方式提及数组(这样它得到默认初始化 – >没有初始化,就像这样: class in_place_string { char data[10]; static struct pre_initialized_type {} pre_initialized; in_plac

  • c – 引用临时变量 – 为什么编译器没有检测到它?2019-08-26 20:09:04

    我希望这不是重复,我已经阅读了一些相关的问题,但似乎没有人涵盖这个案例: #include <iostream> int* return_dangling_p() { int x = 1; return &x; // warning: address of local variable 'x' returned } void some_func() { int x = 2; } int main(in

  • C指针奇怪的未定义行为2019-08-24 18:08:27

    使用-O2(或者-O3)进行编译并运行该程序会在我的机器上产生有趣的结果. #include <iostream> using namespace std; int main() { // Pointer to an int in the heap with a value of 5 int *p = new int(5); // Deallocate the memory, but keep a dangling pointer

  • C联盟成员访问和未定义的行为2019-07-31 01:05:15

    我目前正在开展一个项目,其中提供了以下内容 结构法.我的工作是C,但该项目同时使用C和C.结构相同定义由C和C使用. typedef struct PacketHeader { //Byte 0 uint8_t bRes :4; uint8_t bEmpty :1; uint8_t b

  • c – 在const对象上间接调用非const函数2019-07-30 16:08:50

    给出以下代码: class foo; foo* instance = NULL; class foo { public: explicit foo(int j) : i(j) { instance = this; } void inc() { ++i; } private: int i; }; 以下是使用定义的行为吗? const foo f(0); int main() { instanc

  • nullptr是否在C中引用了未定义的行为?2019-07-29 02:08:09

    参见英文答案 > Assigning a reference by dereferencing a NULL pointer                                    5个 以下代码愚弄nullptr指针和引用: #include <cstdio> void printRefAddr(int &ref) { printf("printAddr %p\n", &ref);

  • c – 抛弃方法的常数2019-07-27 09:08:12

    作为我之前的问题(Writing to class member through const &)的后续,是否也很好地定义并正确抛弃类成员方法的常量? class A { public: A() : a(5) { } int run() const { std::cout << "a: " << a << std::endl; int& x = (in

  • c – gcc是否会跳过此检查以查找有符号整数溢出?2019-07-25 06:07:18

    例如,给出以下代码: int f(int n) { if (n < 0) return 0; n = n + 100; if (n < 0) return 0; return n; } 假设您传入的数字非常接近整数溢出(小于100),编译器是否会生成会给您带来负回报的代码? 以下是Simon Tatham的“The Descent to C”中关

  • python – 赋值的右侧是否总是在赋值之前进行求值?2019-07-25 03:56:54

    这是一段代码片段. x = {} x[1] = len(x) print x {1: 0} 这个定义得很好吗?也就是说,x == {1:1}可以吗? 因为我记得C ’98中的等效程序(如果我们使用std :: map)具有未定义的行为.使用VS编译器和G编译时,程序的输出是不同的.解决方法:正如我在评论中提到的,这个测试用例可以简化为

  • 堆栈和堆之间的区别2019-07-13 07:50:46

    请告诉我堆栈和堆之间的区别与下面的代码 int main() { int arr[3]; int *a; arr [5] = 6; // out of bound but it will not give error. arr [3000] = 8 ; //SIGSEGV a = malloc (sizeof (int)); a[4] = 6; a[4000] = 8; //No error } 我知道a

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有