Skip to content
Snippets Groups Projects
Commit bccec181 authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Notizen und Beispiele 24.4.2023

parent 1fe38f90
Branches
No related tags found
No related merge requests found
Showing
with 1084 additions and 2 deletions
...@@ -41,3 +41,22 @@ Aufgabe: Schreibe ein Progrämmchen, das eine float-Variable lesbar ausgibt, ...@@ -41,3 +41,22 @@ Aufgabe: Schreibe ein Progrämmchen, das eine float-Variable lesbar ausgibt,
Die Aufgabe ist erfüllt, wenn wir die Mantisse (mit Vorzeichen) und den (binären) Die Aufgabe ist erfüllt, wenn wir die Mantisse (mit Vorzeichen) und den (binären)
Exponenten kennen. Um danach die Dezimalzahl korrekt auszugeben, ist auch Exponenten kennen. Um danach die Dezimalzahl korrekt auszugeben, ist auch
Gleitkommaarithmetik sowie printf() mit "%f" (oder besser: "%e") erlaubt. Gleitkommaarithmetik sowie printf() mit "%f" (oder besser: "%e") erlaubt.
Ergebnis:
Format der Fließkommazahl: V EEEEEEEE 1.MMMMMMMMMMMMMMMMMMMMMMM
Fließkommazahl: 6.674300e-11
Bitmuster: 0x2e92c4f8
Vorzeichen: 0
Charakteristik: 93
Exponent, bezogen auf das zweitoberste Bit der Mantisse: -34
Ergebnis: 1.MMMMMMMMMMMMMMMMMMMMMMM · 2^(Charakteristik - B) // B = 127 bei float
Exponent, bezogen auf das unterste Bit der Mantisse: -57
Ergebnis: 1MMMMMMMMMMMMMMMMMMMMMMM.0 · 2^(Charakteristik - B - 23) // B = 127 bei float
Mantisse: 9618680 // bezogen auf das unterste Bit
Ergebnis: 9618680·2^-57
...@@ -6,13 +6,20 @@ ...@@ -6,13 +6,20 @@
int main (void) int main (void)
{ {
float G = 6.6743e-11; float G = 6.6743e-11;
printf ("Fließkommazahl: %e\n", G);
uint32_t *g = (uint32_t *) &G; uint32_t *g = (uint32_t *) &G;
printf ("Bitmuster: 0x%08x\n", *g);
int8_t sign = !!(*g & (1 << 31)); int8_t sign = !!(*g & (1 << 31));
uint8_t ch = (*g >> 23); printf ("Vorzeichen: %d\n", sign);
uint8_t ch = ((*g & 0x7fffffff) >> 23);
printf ("Charakteristik: %d\n", ch);
int ex = ch - B; int ex = ch - B;
printf ("Exponent, bezogen auf das zweitoberste Bit der Mantisse: %d\n", ex);
printf ("Exponent, bezogen auf das unterste Bit der Mantisse: %d\n", ex - 23);
int32_t mant = (*g & 0x7fffff) | 0x800000; int32_t mant = (*g & 0x7fffff) | 0x800000;
printf ("Mantisse: %d\n", mant);
if (sign) if (sign)
mant *= -1; mant *= -1;
printf ("%d·2^%d\n", mant, ex); printf ("Ergebnis: %d·2^%d\n", mant, ex - 23);
return 0; return 0;
} }
#include <stdio.h>
float f (float x)
{
return x * x;
}
int main (void)
{
const float dx = 0.0000001;
float x = 0.9;
printf ("%10f%10f\n", x, f (x));
x += dx;
printf ("%10f%10f\n", x, f (x));
return 0;
}
obj-m += chardev-1.o
obj-m += chardev-2.o
obj-m += chardev-3.o
obj-m += chardev-3x.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
/*
* chardev.c: Creates a read-only char device that says how many times
* you've read from the dev file
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <asm/uaccess.h> /* for put_user */
MODULE_LICENSE("GPL");
/*
* Prototypes - this would normally go in a .h file
*/
int init_module(void);
void cleanup_module(void);
static int device_open(struct inode *, struct file *);
static int device_release(struct inode *, struct file *);
static ssize_t device_read(struct file *, char *, size_t, loff_t *);
static ssize_t device_write(struct file *, const char *, size_t, loff_t *);
#define SUCCESS 0
#define DEVICE_NAME "chardev" /* Dev name as it appears in /proc/devices */
#define BUF_LEN 80 /* Max length of the message from the device */
/*
* Global variables are declared as static, so are global within the file.
*/
static int Major; /* Major number assigned to our device driver */
static int Device_Open = 0; /* Is device open?
* Used to prevent multiple access to device */
static char msg[BUF_LEN]; /* The msg the device will give when asked */
static char *msg_Ptr;
static struct file_operations fops = {
.read = device_read,
.write = device_write,
.open = device_open,
.release = device_release
};
/*
* This function is called when the module is loaded
*/
int init_module(void)
{
Major = register_chrdev(0, DEVICE_NAME, &fops);
if (Major < 0) {
printk(KERN_ALERT "Registering char device failed with %d\n", Major);
return Major;
}
printk(KERN_INFO "I was assigned major number %d. To talk to\n", Major);
printk(KERN_INFO "the driver, create a dev file with\n");
printk(KERN_INFO "'mknod /dev/%s c %d 0'.\n", DEVICE_NAME, Major);
printk(KERN_INFO "Try various minor numbers. Try to cat and echo to\n");
printk(KERN_INFO "the device file.\n");
printk(KERN_INFO "Remove the device file and module when done.\n");
return SUCCESS;
}
/*
* This function is called when the module is unloaded
*/
void cleanup_module(void)
{
/*
* Unregister the device
*/
unregister_chrdev(Major, DEVICE_NAME);
}
/*
* Methods
*/
/*
* Called when a process tries to open the device file, like
* "cat /dev/mycharfile"
*/
static int device_open(struct inode *inode, struct file *file)
{
static int counter = 0;
if (Device_Open)
return -EBUSY;
Device_Open++;
sprintf(msg, "I already told you %d times Hello world!\n", counter++);
msg_Ptr = msg;
try_module_get(THIS_MODULE);
return SUCCESS;
}
/*
* Called when a process closes the device file.
*/
static int device_release(struct inode *inode, struct file *file)
{
Device_Open--; /* We're now ready for our next caller */
/*
* Decrement the usage count, or else once you opened the file, you'll
* never get get rid of the module.
*/
module_put(THIS_MODULE);
return 0;
}
/*
* Called when a process, which already opened the dev file, attempts to
* read from it.
*/
static ssize_t device_read(struct file *filp, /* see include/linux/fs.h */
char *buffer, /* buffer to fill with data */
size_t length, /* length of the buffer */
loff_t *offset)
{
/*
* Number of bytes actually written to the buffer
*/
int bytes_read = 0;
/*
* If we're at the end of the message,
* return 0 signifying end of file
*/
if (*msg_Ptr == 0)
return 0;
/*
* Actually put the data into the buffer
*/
while (length && *msg_Ptr) {
/*
* The buffer is in the user data segment, not the kernel
* segment so "*" assignment won't work. We have to use
* put_user which copies data from the kernel data segment to
* the user data segment.
*/
put_user(*(msg_Ptr++), buffer++);
length--;
bytes_read++;
}
/*
* Most read functions return the number of bytes put into the buffer
*/
return bytes_read;
}
/*
* Called when a process writes to dev file: echo "hi" > /dev/hello
*/
static ssize_t
device_write(struct file *filp, const char *buff, size_t len, loff_t * off)
{
printk(KERN_ALERT "Sorry, this operation isn't supported.\n");
return -EINVAL;
}
[300030.570357] chardev_1: loading out-of-tree module taints kernel.
[300030.570409] chardev_1: module verification failed: signature and/or required key missing - tainting kernel
[300030.570636] I was assigned major number 241. To talk to
[300030.570637] the driver, create a dev file with
[300030.570637] 'mknod /dev/chardev c 241 0'.
[300030.570638] Try various minor numbers. Try to cat and echo to
[300030.570638] the device file.
[300030.570638] Remove the device file and module when done.
cassini/home/peter/bo/2023ss/bs/20230424> mkdir dev
cassini/home/peter/bo/2023ss/bs/20230424> mknod dev/chardev c 241 0
mknod: dev/chardev: Die Operation ist nicht erlaubt
cassini/home/peter/bo/2023ss/bs/20230424> sudo mknod dev/chardev c 241 0
cassini/home/peter/bo/2023ss/bs/20230424> ls -l dev
insgesamt 0
crw-r--r-- 1 root root 241, 0 Apr 24 17:16 chardev
cassini/home/peter/bo/2023ss/bs/20230424>
cassini/home/peter/bo/2023ss/bs/20230424> ls -l dev/
insgesamt 0
crw-r--r-- 1 root root 241, 0 Apr 24 17:16 chardev
cassini/home/peter/bo/2023ss/bs/20230424> #sudo mknod dev/chardev c 241 0
cassini/home/peter/bo/2023ss/bs/20230424> echo "Hallo!" > dev/chardev
bash: dev/chardev: Keine Berechtigung
cassini/home/peter/bo/2023ss/bs/20230424> sudo echo "Hallo!" > dev/chardev
bash: dev/chardev: Keine Berechtigung
cassini/home/peter/bo/2023ss/bs/20230424> echo "Hallo!" | sudo tee dev/chardev
Hallo!
tee: dev/chardev: Das Argument ist ungültig
cassini/home/peter/bo/2023ss/bs/20230424> LANG=C echo "Hallo!" | sudo tee dev/chardev
Hallo!
tee: dev/chardev: Das Argument ist ungültig
cassini/home/peter/bo/2023ss/bs/20230424> echo "Hallo!" | LANG=C sudo tee dev/chardev Hallo!
tee: dev/chardev: Invalid argument
cassini/home/peter/bo/2023ss/bs/20230424>
cassini/home/peter/bo/2023ss/bs/20230424> ls -l dev/
insgesamt 0
crw-r--r-- 1 root root 241, 0 Apr 24 17:16 chardev
cassini/home/peter/bo/2023ss/bs/20230424> cat dev/chardev
I already told you 3 times Hello world!
cassini/home/peter/bo/2023ss/bs/20230424> cat dev/chardev
I already told you 4 times Hello world!
cassini/home/peter/bo/2023ss/bs/20230424>
File moved
/*
* chardev.c: Creates a read-only char device that says how many times
* you've read from the dev file
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <asm/uaccess.h> /* for put_user */
MODULE_LICENSE("GPL");
/*
* Prototypes - this would normally go in a .h file
*/
int init_module(void);
void cleanup_module(void);
static int device_open(struct inode *, struct file *);
static int device_release(struct inode *, struct file *);
static ssize_t device_read(struct file *, char *, size_t, loff_t *);
static ssize_t device_write(struct file *, const char *, size_t, loff_t *);
struct class *dev_Class;
struct device *chr_dev;
#define SUCCESS 0
#define DEVICE_NAME "chardev" /* Dev name as it appears in /proc/devices */
#define BUF_LEN 80 /* Max length of the message from the device */
/*
* Global variables are declared as static, so are global within the file.
*/
static int Major; /* Major number assigned to our device driver */
static int Device_Open = 0; /* Is device open?
* Used to prevent multiple access to device */
static char msg[BUF_LEN]; /* The msg the device will give when asked */
static char *msg_Ptr;
static struct file_operations fops = {
.read = device_read,
.write = device_write,
.open = device_open,
.release = device_release
};
/*
* This function is called when the module is loaded
*/
int init_module(void)
{
Major = register_chrdev(0, DEVICE_NAME, &fops);
if (Major < 0) {
printk(KERN_ALERT "Registering char device failed with %d\n", Major);
return Major;
}
// Create module class
printk (KERN_INFO "Creating device class \"chardev\" ...\n");
dev_Class = class_create (THIS_MODULE,DEVICE_NAME);
if( dev_Class == NULL)
{
printk (KERN_ALERT "Error! Class couldn't be created!\n");
return 1;
}
printk (KERN_INFO "Class created!\n");
// Create device in /dev/...
printk (KERN_INFO "Creating device\n");
chr_dev = device_create (dev_Class, NULL, MKDEV (Major,0), NULL, DEVICE_NAME);
if (chr_dev == NULL)
{
printk( KERN_ALERT "Error! Device couldn't be created!\n" );
return 1 ;
}
return SUCCESS;
}
/*
* This function is called when the module is unloaded
*/
void cleanup_module(void)
{
printk(KERN_INFO "module chardev-3 cleanup\n");
//Unregister the device
if (chr_dev)
{
printk(KERN_INFO "Unregister device ...\n");
device_unregister(chr_dev);
printk(KERN_INFO "OK\n");
}
if (dev_Class)
{
printk(KERN_INFO "Unregister class ...\n");
class_unregister(dev_Class);
printk(KERN_INFO "OK\n");
}
printk(KERN_INFO "Unregister Chardev ...\n");
unregister_chrdev(Major, DEVICE_NAME);
printk(KERN_INFO "Device %s unregistered!\n", DEVICE_NAME);
}
/*
* Methods
*/
/*
* Called when a process tries to open the device file, like
* "cat /dev/mycharfile"
*/
static int device_open(struct inode *inode, struct file *file)
{
static int counter = 0;
if (Device_Open)
return -EBUSY;
Device_Open++;
sprintf(msg, "I already told you %d times Hello world!\n", counter++);
msg_Ptr = msg;
try_module_get(THIS_MODULE);
return SUCCESS;
}
/*
* Called when a process closes the device file.
*/
static int device_release(struct inode *inode, struct file *file)
{
Device_Open--; /* We're now ready for our next caller */
/*
* Decrement the usage count, or else once you opened the file, you'll
* never get get rid of the module.
*/
module_put(THIS_MODULE);
return 0;
}
/*
* Called when a process, which already opened the dev file, attempts to
* read from it.
*/
static ssize_t device_read(struct file *filp, /* see include/linux/fs.h */
char *buffer, /* buffer to fill with data */
size_t length, /* length of the buffer */
loff_t * offset)
{
/*
* Number of bytes actually written to the buffer
*/
int bytes_read = 0;
/*
* If we're at the end of the message,
* return 0 signifying end of file
*/
if (*msg_Ptr == 0)
return 0;
/*
* Actually put the data into the buffer
*/
while (length && *msg_Ptr) {
/*
* The buffer is in the user data segment, not the kernel
* segment so "*" assignment won't work. We have to use
* put_user which copies data from the kernel data segment to
* the user data segment.
*/
put_user(*(msg_Ptr++), buffer++);
length--;
bytes_read++;
}
/*
* Most read functions return the number of bytes put into the buffer
*/
return bytes_read;
}
/*
* Called when a process writes to dev file: echo "hi" > /dev/hello
*/
static ssize_t
device_write(struct file *filp, const char *buff, size_t len, loff_t * off)
{
printk(KERN_ALERT "Sorry, this operation isn't supported.\n");
return -EINVAL;
}
/*
* chardev.c: Creates a read-only char device that says how many times
* you've read from the dev file
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <asm/uaccess.h> /* for put_user */
MODULE_LICENSE("GPL");
/*
* Prototypes - this would normally go in a .h file
*/
int init_module(void);
void cleanup_module(void);
static int device_open(struct inode *, struct file *);
static int device_release(struct inode *, struct file *);
static ssize_t device_read(struct file *, char *, size_t, loff_t *);
static ssize_t device_write(struct file *, const char *, size_t, loff_t *);
struct class *dev_Class;
struct device *chr_dev;
#define SUCCESS 0
#define DEVICE_NAME "chardevx" /* Dev name as it appears in /proc/devices */
#define BUF_LEN 80 /* Max length of the message from the device */
/*
* Global variables are declared as static, so are global within the file.
*/
static int Major; /* Major number assigned to our device driver */
static int Device_Open = 0; /* Is device open?
* Used to prevent multiple access to device */
static char msg[BUF_LEN]; /* The msg the device will give when asked */
static char *msg_Ptr;
static struct file_operations fops = {
.read = device_read,
.write = device_write,
.open = device_open,
.release = device_release
};
/*
* This function is called when the module is loaded
*/
int init_module(void)
{
Major = register_chrdev(0, DEVICE_NAME, &fops);
if (Major < 0) {
printk(KERN_ALERT "Registering char device failed with %d\n", Major);
return Major;
}
// Create module class
printk (KERN_INFO "Creating device class \"chardev\" ...\n");
dev_Class = class_create (THIS_MODULE,DEVICE_NAME);
if( dev_Class == NULL)
{
printk (KERN_ALERT "Error! Class couldn't be created!\n");
return 1;
}
printk (KERN_INFO "Class created!\n");
// Create device in /dev/...
printk (KERN_INFO "Creating device\n");
chr_dev = device_create (dev_Class, NULL, MKDEV (Major,0), NULL, DEVICE_NAME);
if (chr_dev == NULL)
{
printk( KERN_ALERT "Error! Device couldn't be created!\n" );
return 1 ;
}
return SUCCESS;
}
/*
* This function is called when the module is unloaded
*/
void cleanup_module(void)
{
printk(KERN_INFO "module chardev-3 cleanup\n");
//Unregister the device
if (chr_dev)
{
printk(KERN_INFO "Unregister device ...\n");
device_unregister(chr_dev);
printk(KERN_INFO "OK\n");
}
if (dev_Class)
{
printk(KERN_INFO "Unregister class ...\n");
class_unregister(dev_Class);
printk(KERN_INFO "OK\n");
}
printk(KERN_INFO "Unregister Chardev ...\n");
unregister_chrdev(Major, DEVICE_NAME);
printk(KERN_INFO "Device %s unregistered!\n", DEVICE_NAME);
}
/*
* Methods
*/
/*
* Called when a process tries to open the device file, like
* "cat /dev/mycharfile"
*/
static int device_open(struct inode *inode, struct file *file)
{
static int counter = 0;
if (Device_Open)
return -EBUSY;
Device_Open++;
sprintf(msg, "I already told you %d times Hello world!\n", counter++);
msg_Ptr = msg;
try_module_get(THIS_MODULE);
return SUCCESS;
}
/*
* Called when a process closes the device file.
*/
static int device_release(struct inode *inode, struct file *file)
{
Device_Open--; /* We're now ready for our next caller */
/*
* Decrement the usage count, or else once you opened the file, you'll
* never get get rid of the module.
*/
module_put(THIS_MODULE);
return 0;
}
/*
* Called when a process, which already opened the dev file, attempts to
* read from it.
*/
static ssize_t device_read(struct file *filp, /* see include/linux/fs.h */
char *buffer, /* buffer to fill with data */
size_t length, /* length of the buffer */
loff_t * offset)
{
/*
* Number of bytes actually written to the buffer
*/
int bytes_read = 0;
/*
* If we're at the end of the message,
* return 0 signifying end of file
*/
if (*msg_Ptr == 0)
return 0;
/*
* Actually put the data into the buffer
*/
while (length && *msg_Ptr) {
/*
* The buffer is in the user data segment, not the kernel
* segment so "*" assignment won't work. We have to use
* put_user which copies data from the kernel data segment to
* the user data segment.
*/
put_user(*(msg_Ptr++), buffer++);
length--;
bytes_read++;
}
/*
* Most read functions return the number of bytes put into the buffer
*/
return bytes_read;
}
/*
* Called when a process writes to dev file: echo "hi" > /dev/hello
*/
static ssize_t
device_write(struct file *filp, const char *buff, size_t len, loff_t * off)
{
printk(KERN_ALERT "Sorry, this operation isn't supported.\n");
return -EINVAL;
}
/*
* chardev.c: Creates a read-only char device that says how many times
* you've read from the dev file
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <asm/uaccess.h> /* for put_user */
MODULE_LICENSE("GPL");
/*
* Prototypes - this would normally go in a .h file
*/
int init_module(void);
void cleanup_module(void);
static int device_open(struct inode *, struct file *);
static int device_release(struct inode *, struct file *);
static ssize_t device_read(struct file *, char *, size_t, loff_t *);
static ssize_t device_write(struct file *, const char *, size_t, loff_t *);
struct class *dev_Class;
struct device *chr_dev;
#define SUCCESS 0
#define DEVICE_NAME "chardev" /* Dev name as it appears in /proc/devices */
#define BUF_LEN 80 /* Max length of the message from the device */
/*
* Global variables are declared as static, so are global within the file.
*/
static int Major; /* Major number assigned to our device driver */
static int Device_Open = 0; /* Is device open?
* Used to prevent multiple access to device */
static char msg[BUF_LEN]; /* The msg the device will give when asked */
static char *msg_Ptr;
static struct file_operations fops = {
.read = device_read,
.write = device_write,
.open = device_open,
.release = device_release
};
/*
* This function is called when the module is loaded
*/
int init_module(void)
{
Major = register_chrdev(0, DEVICE_NAME, &fops);
if (Major < 0) {
printk(KERN_ALERT "Registering char device failed with %d\n", Major);
return Major;
}
// Create module class
printk (KERN_INFO "Creating device class \"chardev\" ...\n");
dev_Class = class_create (THIS_MODULE,DEVICE_NAME);
if( dev_Class == NULL)
{
printk (KERN_ALERT "Error! Class couldn't be created!\n");
return 1;
}
printk (KERN_INFO "Class created!\n");
// Create device in /dev/...
printk (KERN_INFO "Creating device\n");
chr_dev = device_create (dev_Class, NULL, MKDEV (Major,0), NULL, DEVICE_NAME);
if (chr_dev == NULL)
{
printk( KERN_ALERT "Error! Device couldn't be created!\n" );
return 1 ;
}
return SUCCESS;
}
/*
* This function is called when the module is unloaded
*/
void cleanup_module(void)
{
printk(KERN_INFO "module chardev-4 cleanup\n");
//Unregister the device
if (chr_dev)
{
printk(KERN_INFO "Unregister device ...\n");
device_unregister(chr_dev);
printk(KERN_INFO "OK\n");
}
if (dev_Class)
{
printk(KERN_INFO "Unregister class ...\n");
class_unregister(dev_Class);
printk(KERN_INFO "OK\n");
}
printk(KERN_INFO "Unregister Chardev ...\n");
unregister_chrdev(Major, DEVICE_NAME);
printk(KERN_INFO "Device %s unregistered!\n", DEVICE_NAME);
}
/*
* Methods
*/
/*
* Called when a process tries to open the device file, like
* "cat /dev/mycharfile"
*/
static int device_open(struct inode *inode, struct file *file)
{
static int counter = 0;
if (Device_Open)
return -EBUSY;
Device_Open++;
sprintf(msg, "I already told you %d times Hello world!\n", counter++);
msg_Ptr = msg;
try_module_get(THIS_MODULE);
return SUCCESS;
}
/*
* Called when a process closes the device file.
*/
static int device_release(struct inode *inode, struct file *file)
{
Device_Open--; /* We're now ready for our next caller */
/*
* Decrement the usage count, or else once you opened the file, you'll
* never get get rid of the module.
*/
module_put(THIS_MODULE);
return 0;
}
/*
* Called when a process, which already opened the dev file, attempts to
* read from it.
*/
static ssize_t device_read(struct file *filp, /* see include/linux/fs.h */
char *buffer, /* buffer to fill with data */
size_t length, /* length of the buffer */
loff_t * offset)
{
/*
* Number of bytes actually written to the buffer
*/
int bytes_read = 0;
/*
* If we're at the end of the message,
* return 0 signifying end of file
*/
if (*msg_Ptr == 0)
return 0;
/*
* Actually put the data into the buffer
*/
while (length && *msg_Ptr) {
/*
* The buffer is in the user data segment, not the kernel
* segment so "*" assignment won't work. We have to use
* put_user which copies data from the kernel data segment to
* the user data segment.
*/
/* put_user(*(msg_Ptr++), buffer++); */
*buffer++ = *(msg_Ptr++); /* Sicherheitsloch! */
length--;
bytes_read++;
}
/*
* Most read functions return the number of bytes put into the buffer
*/
return bytes_read;
}
/*
* Called when a process writes to dev file: echo "hi" > /dev/hello
*/
static ssize_t
device_write(struct file *filp, const char *buff, size_t len, loff_t * off)
{
printk(KERN_ALERT "Sorry, this operation isn't supported.\n");
return -EINVAL;
}
#include <stdio.h>
int main (void)
{
float fifth = 1.0 / 5.0;
printf ("1/5 = %f\n", fifth);
return 0;
}
.file "floats-08.c"
.text
.section .rodata.str1.1,"aMS",@progbits,1
.LC1:
.string "1/5 = %f\n"
.text
.globl main
.type main, @function
main:
.LFB11:
.cfi_startproc
subq $8, %rsp
.cfi_def_cfa_offset 16
movsd .LC0(%rip), %xmm0
leaq .LC1(%rip), %rdi
movl $1, %eax
call printf@PLT
movl $0, %eax
addq $8, %rsp
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE11:
.size main, .-main
.section .rodata.cst8,"aM",@progbits,8
.align 8
.LC0:
.long 2684354560
.long 1070176665
.ident "GCC: (Debian 8.3.0-6) 8.3.0"
.section .note.GNU-stack,"",@progbits
#include <stdio.h>
int main (void)
{
volatile float fifth = 1.0 / 5.0;
printf ("1/5 = %f\n", fifth);
return 0;
}
.file "floats-09.c"
.text
.section .rodata.str1.1,"aMS",@progbits,1
.LC1:
.string "1/5 = %f\n"
.text
.globl main
.type main, @function
main:
.LFB11:
.cfi_startproc
subq $24, %rsp
.cfi_def_cfa_offset 32
movss .LC0(%rip), %xmm0
movss %xmm0, 12(%rsp)
movss 12(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq .LC1(%rip), %rdi
movl $1, %eax
call printf@PLT
movl $0, %eax
addq $24, %rsp
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE11:
.size main, .-main
.section .rodata.cst4,"aM",@progbits,4
.align 4
.LC0:
.long 1045220557
.ident "GCC: (Debian 8.3.0-6) 8.3.0"
.section .note.GNU-stack,"",@progbits
#include <gtk/gtk.h>
int main (int argc, char **argv)
{
gtk_init (&argc, &argv);
GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Hello");
gtk_widget_show (window);
gtk_main ();
return 0;
}
#include <gtk/gtk.h>
int main (int argc, char **argv)
{
gtk_init (&argc, &argv);
GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Hello");
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
gtk_widget_show (window);
gtk_main ();
return 0;
}
#include <gtk/gtk.h>
int main (int argc, char **argv)
{
gtk_init (&argc, &argv);
GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Hello");
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
GtkWidget *button = gtk_button_new_with_label ("Quit");
g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL);
gtk_container_add (GTK_CONTAINER (window), button);
gtk_widget_show (button);
gtk_widget_show (window);
gtk_main ();
return 0;
}
#include <gtk/gtk.h>
int main (int argc, char **argv)
{
gtk_init (&argc, &argv);
GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Hello");
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
gtk_container_add (GTK_CONTAINER (window), vbox);
GtkWidget *button = gtk_button_new_with_label ("Quit");
g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL);
gtk_container_add (GTK_CONTAINER (vbox), button);
GtkWidget *drawing_area = gtk_drawing_area_new ();
gtk_container_add (GTK_CONTAINER (vbox), drawing_area);
gtk_widget_show (drawing_area);
gtk_widget_show (button);
gtk_widget_show (vbox);
gtk_widget_show (window);
gtk_main ();
return 0;
}
#include <gtk/gtk.h>
int main (int argc, char **argv)
{
gtk_init (&argc, &argv);
GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Hello");
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
gtk_container_add (GTK_CONTAINER (window), vbox);
GtkWidget *button = gtk_button_new_with_label ("Quit");
g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL);
gtk_container_add (GTK_CONTAINER (vbox), button);
GtkWidget *drawing_area = gtk_drawing_area_new ();
gtk_container_add (GTK_CONTAINER (vbox), drawing_area);
gtk_widget_set_size_request (drawing_area, 100, 100);
gtk_widget_show (drawing_area);
gtk_widget_show (button);
gtk_widget_show (vbox);
gtk_widget_show (window);
gtk_main ();
return 0;
}
#include <gtk/gtk.h>
gboolean draw (GtkWidget *widget, cairo_t *c, gpointer data)
{
GdkRGBA red = { 1.0, 0.0, 0.0, 0.8 };
GdkRGBA yellow = { 1.0, 1.0, 0.0, 0.6 };
GdkRGBA blue = { 0.0, 0.5, 1.0, 0.4 };
gdk_cairo_set_source_rgba (c, &red);
cairo_rectangle (c, 10, 10, 60, 40);
cairo_fill (c);
gdk_cairo_set_source_rgba (c, &yellow);
cairo_arc (c, 65, 50, 30, 0, 2 * G_PI);
cairo_fill (c);
gdk_cairo_set_source_rgba (c, &blue);
cairo_move_to (c, 10, 70);
cairo_line_to (c, 70, 70);
cairo_line_to (c, 40, 18);
cairo_close_path (c);
cairo_fill (c);
return FALSE; /* TRUE to stop other handlers from being invoked for the event.
FALSE to propagate the event further. */
}
int main (int argc, char **argv)
{
gtk_init (&argc, &argv);
GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Hello");
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
gtk_container_add (GTK_CONTAINER (window), vbox);
GtkWidget *button = gtk_button_new_with_label ("Quit");
g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL);
gtk_container_add (GTK_CONTAINER (vbox), button);
GtkWidget *drawing_area = gtk_drawing_area_new ();
gtk_container_add (GTK_CONTAINER (vbox), drawing_area);
g_signal_connect (drawing_area, "draw", G_CALLBACK (draw), NULL);
gtk_widget_set_size_request (drawing_area, 100, 100);
gtk_widget_show (drawing_area);
gtk_widget_show (button);
gtk_widget_show (vbox);
gtk_widget_show (window);
gtk_main ();
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment